distofintervall

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 3.9, Creation date: 2017-05-31, Last change: 2025-09-14

distance within an intervall

Description

maps a value in circular intervall

See Also:

Example Illustration

 missing image of distofintervall(a,b,inter)

Syntax

[d,iv]=distofintervall(a,b,[inter])

Input Parameter

a: value 1
b: value 2
inter: intervall; default is [-pi +pi]

Output Parameter

d: distance ()
iv: value a in intervall

Examples


distofintervall (-pi+pi/10,pi-pi/10)
distofintervall (1:10,2:11)
distofintervall (-pi/2,pi/1.5)




Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This algorithm calculates the distance between two values within a circular interval. It is designed to handle values that wrap around, such as angles in radians.

Input Parameters

Output Results

Algorithm Steps

  1. Initialize the interval to [-À, +À] unless a different interval is provided.
  2. Calculate the range of the interval, br = inter(2) - inter(1).
  3. For each pair of values in 'a' and 'b', call the helper function dofi to compute the distance and adjust the values.
  4. In the dofi function:
    • Adjust 'a' and 'b' to start from the beginning of the interval.
    • Use the modulo operation to wrap the values within the interval range.
    • Swap 'a' and 'b' if 'a' is greater than 'b' to ensure correct distance calculation.
    • Calculate two possible distances: d1 (direct distance) and d2 (wrap-around distance).
    • Select the minimum of the two distances as the result.
    • Swap back 'a' and 'b' if they were swapped earlier.
  5. Return the calculated distance and the adjusted values.

Example Usage

Example 1: a = distofintervall(-À + À/10, À - À/10)

Example 2: a = distofintervall(1:10, 2:11)

Algorithm explaination created using ChatGPT on 2025-08-19 01:35. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21