forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapAngle.mo
26 lines (24 loc) · 1.25 KB
/
wrapAngle.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
within Modelica.Math;
function wrapAngle "Wrap angle to interval ]-pi,pi] or [0,2*pi["
extends Modelica.Math.Icons.AxisCenter;
import Modelica.Constants.pi;
input Modelica.Units.SI.Angle u "Input angle";
input Boolean positiveRange=false "Use only positive output range, if true";
output Modelica.Units.SI.Angle y "Wrapped output angle";
algorithm
y :=mod(u, 2*pi);
if y>pi and not positiveRange then
y := y - 2*pi;
end if;
annotation (Icon(graphics={
Line(points={{-90,0},{68,0}}, color={192,192,192}),
Polygon(
points={{90,0},{68,8},{68,-8},{90,0}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-80,54},{-80,54},{-60,80},{-60,-80},{60,80},{60,-80},{80,-52}})}),
Documentation(info= "<html><head></head><body><p>
This function wraps the input angle <code>u</code> to the <a href=\"https://en.wikipedia.org/wiki/Interval_(mathematics)#Notations_for_intervals\">interval</a> ]-pi,pi], if <code>positiveRange == false</code>.
Otherwise the input angle <code>u</code> is wrapped to the <a href=\"https://en.wikipedia.org/wiki/Interval_(mathematics)#Notations_for_intervals\">interval</a> [0,2*pi[.</p></body></html>"));
end wrapAngle;