angleshift

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Analytical Geometry
Introduced first in SolidGeometry 5.1, Creation date: 2021-12-14, Last change: 2025-09-15

shifts an agle value into a fixed interval such as [-pi..+pi] or [0 2*pi]



See Also: isincirclesegment , CPLcrosscircseg , cplot , angleinterv , circlesegmentofPL

Example Illustration

 missing image of angleshift(AL,ival)

Syntax

AL=angleshift(AL,[ival])

Input Parameter

AL: List of angle values
ival: [-pi..+pi] or [0 2*pi]; or [ival ival+2*pi]; default is [0 2*pi]

Output Parameter

AL: Alle values inside the allowed interval

Examples


AL=rand(10,2)*3*pi,
angleshift(AL)
angleshift(AL,[pi +pi) % [-pi ... pi]
angleshift(AL,[0 2*pi]) % [0 ...2*pi]
angleshift(AL,2) % [2 ... 2+2*pi]




Copyright 2021-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 function, angleshift, is designed to shift angle values into a specified interval. It is part of the SolidGeometry library and was introduced in version 5.1.

Input Parameters

Output Results

Algorithm Steps

  1. Store the original angle list AL in ALorg.
  2. Determine the interval ival using the function getfuncparams. If ival is a single value, extend it to a full interval by adding 2*pi.
  3. Iterate over each angle in AL:
    • If an angle is less than the lower bound of ival, add 2*pi until it falls within the interval.
    • If an angle is greater than the upper bound of ival, subtract 2*pi until it falls within the interval.
  4. If no output is requested (nargout==0), print a debug message showing the interval and display a table comparing original and new angle values.

Example Usage

AL = rand(10,2) * 3 * pi;
angleshift(AL);
angleshift(AL, [-pi +pi]);  % Shifts angles to [-pi ... pi]
angleshift(AL, [0 2*pi]);   % Shifts angles to [0 ... 2*pi]
angleshift(AL, 2);          % Shifts angles to [2 ... 2+2*pi]
Algorithm explaination created using ChatGPT on 2025-08-19 01:17. (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