View Javadoc
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    * Normalization of angles.
10   * <p>
11   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="http://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="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="http://www.tudelft.nl/pknoppers">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 ValueException in case of error
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  }