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
- a: The first value or array of values.
- b: The second value or array of values.
- inter: The interval within which the values are considered. The default interval is [-Ã, +Ã].
Output Results
- d: The calculated distance between the values within the interval.
- iv: The values of 'a' and 'b' adjusted to fit within the interval.
Algorithm Steps
- Initialize the interval to [-Ã, +Ã] unless a different interval is provided.
- Calculate the range of the interval,
br = inter(2) - inter(1)
.
- For each pair of values in 'a' and 'b', call the helper function
dofi
to compute the distance and adjust the values.
- 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.
- 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