1 package org.djunits.demo.examples;
2
3 import org.djunits.unit.AngleUnit;
4 import org.djunits.value.AngleUtil;
5 import org.djunits.value.ValueException;
6 import org.djunits.value.vdouble.scalar.Angle;
7
8
9
10
11
12
13
14
15
16
17
18 public class Angles
19 {
20
21
22
23
24
25 public static void main(final String[] args) throws ValueException
26 {
27 System.out.println("Normalization of an angle adds or subtracts a multiple of 2\u03c0. For linear angle units "
28 + "the result is a value between 0 and +2\u03c0.");
29 System.out.println("Angles not between -90\u00b0 and +90\u00b0, -\u03c0/2 and +\u03c0/2 cannot properly be "
30 + "expressed as percentage.");
31 Angle a1 = new Angle(3 * Math.PI, AngleUnit.RADIAN);
32 Angle normA1 = AngleUtil.normalize(a1);
33 System.out.println("3 * \u03c0: " + a1 + " (" + a1.toString(AngleUnit.DEGREE) + ", " + a1.toString(AngleUnit.PERCENT)
34 + ") -> " + normA1 + " (" + normA1.toString(AngleUnit.DEGREE) + ", " + normA1.toString(AngleUnit.PERCENT)
35 + ") Note: percentage almost 0");
36 Angle a2 = new Angle(-Math.PI, AngleUnit.RADIAN);
37 Angle normA2 = AngleUtil.normalize(a2);
38 System.out.println(" -\u03c0: " + a2 + " (" + a2.toString(AngleUnit.DEGREE) + ", " + a2.toString(AngleUnit.PERCENT)
39 + ") -> " + normA2 + " (" + normA2.toString(AngleUnit.DEGREE) + ", " + normA2.toString(AngleUnit.PERCENT)
40 + ") Note: percentage almost 0");
41 Angle a3 = new Angle(-45, AngleUnit.DEGREE);
42 Angle normA3 = AngleUtil.normalize(a3);
43 System.out
44 .println(" -45\u0090: " + a3 + " (" + a3.toString(AngleUnit.RADIAN) + ", " + a3.toString(AngleUnit.PERCENT)
45 + ") -> " + normA3 + " (" + normA3.toString(AngleUnit.RADIAN) + ", "
46 + normA3.toString(AngleUnit.PERCENT) + ")");
47 System.out.println("");
48 System.out.println("Angles expressed as percentage are always between -inf and +inf (-90\u00b0 and +90\u00b0, "
49 + "-\u03c0/2 and +\u03c0/2); even after normalization.");
50 Angle a4 = new Angle(-100, AngleUnit.PERCENT);
51 Angle normA4 = AngleUtil.normalize(a4);
52 System.out.println("-100%: " + a4 + " (" + a4.toString(AngleUnit.DEGREE) + ", " + a4.toString(AngleUnit.RADIAN)
53 + ") -> " + normA4 + " (" + normA4.toString(AngleUnit.DEGREE) + ", " + normA4.toString(AngleUnit.RADIAN) + ")");
54 Angle a5 = new Angle(100, AngleUnit.PERCENT);
55 Angle normA5 = AngleUtil.normalize(a5);
56 System.out.println(" 100%: " + a5 + " (" + a5.toString(AngleUnit.DEGREE) + ", " + a5.toString(AngleUnit.RADIAN)
57 + ") -> " + normA5 + " (" + normA5.toString(AngleUnit.DEGREE) + ", " + normA5.toString(AngleUnit.RADIAN) + ")");
58 Angle a6 = new Angle(1000, AngleUnit.PERCENT);
59 Angle normA6 = AngleUtil.normalize(a6);
60 System.out.println("1000%: " + a6 + " (" + a6.toString(AngleUnit.DEGREE) + ", " + a6.toString(AngleUnit.RADIAN)
61 + ") -> " + normA6 + " (" + normA6.toString(AngleUnit.DEGREE) + ", " + normA6.toString(AngleUnit.RADIAN) + ")");
62 }
63
64 }