View Javadoc
1   package org.djunits.demo.examples;
2   
3   import org.djunits.unit.AngleUnit;
4   import org.djunits.value.ValueRuntimeException;
5   import org.djunits.value.util.AngleUtil;
6   import org.djunits.value.vdouble.scalar.Angle;
7   
8   /**
9    * Normalization of angles.
10   * <p>
11   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
13   * <p>
14   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Oct 28, 2015 <br>
15   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
17   */
18  public class Angles
19  {
20      /**
21       * Create some Angle values to demonstrate conversion from and to related units, including the non-linear AngleUnit.PERCENT.
22       * @param args String[]; the command line arguments; not used
23       * @throws ValueRuntimeException in case of error
24       */
25      public static void main(final String[] args) throws ValueRuntimeException
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.println(
44                  "  -45\u0090: " + a3 + " (" + a3.toString(AngleUnit.RADIAN) + ", " + a3.toString(AngleUnit.PERCENT) + ") -> "
45                          + normA3 + " (" + normA3.toString(AngleUnit.RADIAN) + ", " + normA3.toString(AngleUnit.PERCENT) + ")");
46          System.out.println("");
47          System.out.println("Angles expressed as percentage are always between -inf and +inf (-90\u00b0 and +90\u00b0, "
48                  + "-\u03c0/2 and +\u03c0/2); even after normalization.");
49          Angle a4 = new Angle(-100, AngleUnit.PERCENT);
50          Angle normA4 = AngleUtil.normalize(a4);
51          System.out.println("-100%: " + a4 + " (" + a4.toString(AngleUnit.DEGREE) + ", " + a4.toString(AngleUnit.RADIAN)
52                  + ") -> " + normA4 + " (" + normA4.toString(AngleUnit.DEGREE) + ", " + normA4.toString(AngleUnit.RADIAN) + ")");
53          Angle a5 = new Angle(100, AngleUnit.PERCENT);
54          Angle normA5 = AngleUtil.normalize(a5);
55          System.out.println(" 100%: " + a5 + " (" + a5.toString(AngleUnit.DEGREE) + ", " + a5.toString(AngleUnit.RADIAN)
56                  + ") -> " + normA5 + " (" + normA5.toString(AngleUnit.DEGREE) + ", " + normA5.toString(AngleUnit.RADIAN) + ")");
57          Angle a6 = new Angle(1000, AngleUnit.PERCENT);
58          Angle normA6 = AngleUtil.normalize(a6);
59          System.out.println("1000%: " + a6 + " (" + a6.toString(AngleUnit.DEGREE) + ", " + a6.toString(AngleUnit.RADIAN)
60                  + ") -> " + normA6 + " (" + normA6.toString(AngleUnit.DEGREE) + ", " + normA6.toString(AngleUnit.RADIAN) + ")");
61      }
62  
63  }