View Javadoc
1   package demo;
2   
3   
4   import org.djutils.draw.point.OrientedPoint2d;
5   import org.djutils.draw.point.Point2d;
6   
7   /**
8    * PointDemos.java.
9    * <p>
10   * Copyright (c) 2020-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="https://djutils.org/docs/current/djutils/licenses.html">DJUTILS License</a>.
12   * </p>
13   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
14   * @author <a href="https://www.tudelft.nl/pknoppers">Peter Knoppers</a>
15   */
16  public final class PointDemos
17  {
18      /**
19       * Do not instantiate.
20       */
21      private PointDemos()
22      {
23          // Do not instantiate
24      }
25  
26      /**
27       * Demonstrate the Point classes.
28       * @param args String[]; the command line arguments; not used
29       */
30      public static void main(final String[] args)
31      {
32          Point2d point1 = new Point2d(123.45, 234.56);
33          System.out.println(point1);
34          double[] coordinates = new double[] { 123.45, 234.56 };
35          Point2d point2 = new Point2d(coordinates);
36          System.out.println(point2);
37          java.awt.geom.Point2D awtPoint2D = new java.awt.geom.Point2D.Double(123.45, 234.56);
38          Point2d point3 = new Point2d(awtPoint2D);
39          System.out.println(point3);
40          java.awt.geom.Point2D awtPoint2DCopy = point3.toPoint2D();
41          System.out.println(awtPoint2DCopy);
42          
43          Point2d secondPoint2d = new Point2d(234.56, 345.78);
44          System.out.println("Direction to: " + point1.directionTo(secondPoint2d));
45          System.out.println("Distance: " + point1.distance(secondPoint2d));
46          System.out.println("Distance squared " + point1.distanceSquared(secondPoint2d));
47          System.out.println("Interpolation at fraction 0.3: " + point1.interpolate(secondPoint2d, 0.3));
48          
49          System.out.println("Almost equals to another Point2d: " + point1.epsilonEquals(new Point2d(123, 235), 0.5));
50          
51          System.out.println("The point: " + point1);
52          System.out.println("The point translated over 10, -20: " + point1.translate(10, -20));
53          System.out.println("The point scaled by 2: " + point1.scale(2.0));
54          System.out.println("The point negated: " + point1.neg());
55          System.out.println("The point normalized: " + point1.normalize());
56          System.out.println("The point with absolute values: " + point1.abs());
57          System.out.println("The point negated, then absolute: " + point1.neg().abs());
58          
59          OrientedPoint2d orientedPoint2d = new OrientedPoint2d(123.45, 234.56, -0.2);
60          System.out.println(orientedPoint2d);
61      }
62  }