Home > matGeom > geom2d > normalizeAngle.m

normalizeAngle

PURPOSE ^

NORMALIZEANGLE Normalize an angle value within a 2*PI interval.

SYNOPSIS ^

function alpha = normalizeAngle(alpha, varargin)

DESCRIPTION ^

NORMALIZEANGLE  Normalize an angle value within a 2*PI interval.

   ALPHA2 = normalizeAngle(ALPHA);
   ALPHA2 is the same as ALPHA modulo 2*PI and is positive.

   ALPHA2 = normalizeAngle(ALPHA, CENTER);
   Specifies the center of the angle interval.
   If CENTER==0, the interval is [-pi ; +pi]
   If CENTER==PI, the interval is [0 ; 2*pi] (default).

   Example:
   % normalization between 0 and 2*pi (default)
   normalizeAngle(5*pi)
   ans =
       3.1416

   % normalization between -pi and +pi
   normalizeAngle(7*pi/2, 0)
   ans =
       -1.5708

   See also
   vectorAngle, lineAngle

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function alpha = normalizeAngle(alpha, varargin)
0002 %NORMALIZEANGLE  Normalize an angle value within a 2*PI interval.
0003 %
0004 %   ALPHA2 = normalizeAngle(ALPHA);
0005 %   ALPHA2 is the same as ALPHA modulo 2*PI and is positive.
0006 %
0007 %   ALPHA2 = normalizeAngle(ALPHA, CENTER);
0008 %   Specifies the center of the angle interval.
0009 %   If CENTER==0, the interval is [-pi ; +pi]
0010 %   If CENTER==PI, the interval is [0 ; 2*pi] (default).
0011 %
0012 %   Example:
0013 %   % normalization between 0 and 2*pi (default)
0014 %   normalizeAngle(5*pi)
0015 %   ans =
0016 %       3.1416
0017 %
0018 %   % normalization between -pi and +pi
0019 %   normalizeAngle(7*pi/2, 0)
0020 %   ans =
0021 %       -1.5708
0022 %
0023 %   See also
0024 %   vectorAngle, lineAngle
0025 %
0026 
0027 % ------
0028 % Author: David Legland
0029 % e-mail: david.legland@nantes.inra.fr
0030 % Created: 2008-03-10,    using Matlab 7.4.0.287 (R2007a)
0031 % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas.
0032 
0033 % HISTORY
0034 % 2010-03-31 rename as normalizeAngle, and add psb to specify interval
0035 %   center
0036 
0037 center = pi;
0038 if ~isempty(varargin)
0039     center = varargin{1};
0040 end
0041 
0042 alpha = mod(alpha-center+pi, 2*pi) + center-pi;

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019