1
2
3
4
5
6
7
8
9
10
11 package nl.tudelft.simulation.language.d2;
12
13 import java.awt.geom.Point2D;
14
15 /***
16 * <br>
17 * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
18 * University of Technology </a>, the Netherlands. <br>
19 * See for project information <a href="http://www.simulation.tudelft.nl">
20 * www.simulation.tudelft.nl </a> <br>
21 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
22 * License (GPL) </a>, no warranty <br>
23 *
24 * @version Jun 13, 2004 <br>
25 * @author <a
26 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
27 * Verbraeck </a>
28 */
29 public final class Angle
30 {
31 /***
32 * constructs a new Angle
33 */
34 private Angle()
35 {
36 super();
37
38 }
39
40 /***
41 * Normalize an angle between 0 and 2*pi
42 *
43 * @param angle the angle to normalize
44 * @return normalized angle
45 */
46 public static double normalize2Pi(final double angle)
47 {
48 double result = angle + 2.0d * Math.PI;
49 double times = Math.floor(result / (2.0d * Math.PI));
50 result -= times * 2.0d * Math.PI;
51 return result;
52 }
53
54 /***
55 * Normalize an angle between -pi and +pi
56 *
57 * @param angle the angle to normalize
58 * @return normalized angle
59 */
60 public static double normalizePi(final double angle)
61 {
62 double result = angle + 2.0d * Math.PI;
63 double times = Math.floor((result + Math.PI) / (2.0d * Math.PI));
64 result -= times * 2.0d * Math.PI;
65 return result;
66 }
67
68 /***
69 * Return the 2-pi normalized angle when making an arc from p0 to p1
70 *
71 * @param p0 first point
72 * @param p1 second point
73 * @return the normalized angle
74 */
75 public static double angle(final Point2D p0, final Point2D p1)
76 {
77 return normalize2Pi(Math.atan2(p1.getY() - p0.getY(), p1.getX()
78 - p0.getX()));
79 }
80 }