Class DirectedPoint2d

java.lang.Object
org.djutils.draw.point.Point2d
org.djutils.draw.point.DirectedPoint2d
All Implemented Interfaces:
Serializable, Iterable<Point2d>, Directed<DirectedPoint2d>, Directed2d<DirectedPoint2d>, Drawable<Point2d>, Drawable2d, Point<Point2d>
Direct Known Subclasses:
Ray2d

public class DirectedPoint2d extends Point2d implements Directed2d<DirectedPoint2d>
A DirectedPoint2d is a Point2d that additionally carries a direction in 2d-space (dirZ). This is not the direction that the point is when viewed from the origin (0,0).

Copyright (c) 2023-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
See Also:
  • Field Details

    • dirZ

      public final double dirZ
      The counter-clockwise rotation around the point in radians.
  • Constructor Details

    • DirectedPoint2d

      public DirectedPoint2d(double x, double y, double dirZ)
      Construct a new DirectedPoint2d with an x and y coordinate and a direction.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      dirZ - the counter-clockwise rotation around the point in radians
      Throws:
      IllegalArgumentException - when any coordinate or dirZ is NaN
    • DirectedPoint2d

      public DirectedPoint2d(double[] xy, double dirZ)
      Construct a new DirectedPoint2d from an x and y coordinates in a double[] and a direction.
      Parameters:
      xy - the x and y coordinates in that order
      dirZ - the counter-clockwise rotation around the point in radians
      Throws:
      NullPointerException - when xy is null
      ArithmeticException - when any value in xy is NaN or rotZ is NaN
      IllegalArgumentException - when the length of xy is not 2
    • DirectedPoint2d

      public DirectedPoint2d(Point2D point, double dirZ)
      Construct a new DirectedPoint2d from an AWT Point2D and a direction.
      Parameters:
      point - java.awt.geom.Point2D
      dirZ - the counter-clockwise rotation around the point in radians
      Throws:
      NullPointerException - when point is null
      ArithmeticException - when rotZ is NaN
    • DirectedPoint2d

      public DirectedPoint2d(Point2d point, double dirZ)
      Construct a new DirectedPoint2d from a Point2d and a direction.
      Parameters:
      point - a point (with or without orientation)
      dirZ - the counter-clockwise rotation around the point in radians
      Throws:
      NullPointerException - when point is null
      ArithmeticException - when rotZ is NaN
    • DirectedPoint2d

      public DirectedPoint2d(double x, double y, double throughX, double throughY)
      Construct a new DirectedPoint2d from two coordinates and the coordinates of a point that the direction goes through.
      Parameters:
      x - the x coordinate of the of the new DirectedPoint
      y - the y coordinate of the of the new DirectedPoint
      throughX - the x-coordinate of a point that the direction goes through
      throughY - the y-coordinate of a point that the direction goes through
      Throws:
      ArithmeticException - when throughX, or throughY is null
      IllegalArgumentException - when throughX == x and throughY == y
    • DirectedPoint2d

      public DirectedPoint2d(Point2d point, Point2d throughPoint)
      Construct a new DirectedPoint2d from a Point2d and a point that the direction goes through.
      Parameters:
      point - the point
      throughPoint - the point that the direction goes through
      Throws:
      NullPointerException - when point is null, or throughPoint == null
      IllegalArgumentException - when throughX == point.x and throughY == point.y
    • DirectedPoint2d

      public DirectedPoint2d(Point2d point, double throughX, double throughY)
      Construct a new DirectedPoint2d from a Point2d and the coordinates of a point that the direction goes through.
      Parameters:
      point - the point
      throughX - the x coordinate of a point that the direction goes through
      throughY - the y coordinate of a point that the direction goes through
      Throws:
      NullPointerException - when point is null
      ArithmeticException - when throughX, or throughY is NaN
      IllegalArgumentException - when throughX == point.x and throughY == point.y
  • Method Details

    • translate

      public DirectedPoint2d translate(double dX, double dY)
      Description copied from class: Point2d
      Return a new Point2d with a translation by the provided dx and dy.
      Overrides:
      translate in class Point2d
      Parameters:
      dX - the x translation
      dY - the y translation
      Returns:
      a new point with the translated coordinates
    • translate

      public DirectedPoint3d translate(double dX, double dY, double z) throws ArithmeticException, IllegalArgumentException
      Description copied from class: Point2d
      Return a new Point3d with a translation by the provided dx, dy and dz. If this is an OrientedPoint2d, then the result is an OrientedPoint3d with rotX copied from this and rotY and rotZ are set to 0.0.
      Overrides:
      translate in class Point2d
      Parameters:
      dX - the x translation
      dY - the y translation
      z - the z translation
      Returns:
      a new point with the translated coordinates
      Throws:
      IllegalArgumentException - when dX, dY, or dZ is NaN
      ArithmeticException
    • scale

      public DirectedPoint2d scale(double factor) throws IllegalArgumentException
      Description copied from interface: Point
      Return a new Point with the coordinates of this point scaled by the provided factor.
      Specified by:
      scale in interface Point<Point2d>
      Overrides:
      scale in class Point2d
      Parameters:
      factor - the scale factor
      Returns:
      a new point with the coordinates of this point scaled by the provided factor
      Throws:
      IllegalArgumentException
    • neg

      public DirectedPoint2d neg()
      Description copied from interface: Point
      Return a new Point with negated coordinate values. If this is a DirectedPoint, dirY (in case this is a DirectedPoint3d and dirZ are negated.
      Specified by:
      neg in interface Directed<DirectedPoint2d>
      Specified by:
      neg in interface Point<Point2d>
      Overrides:
      neg in class Point2d
      Returns:
      a new point with negated coordinate values
    • abs

      public DirectedPoint2d abs()
      Description copied from interface: Point
      Return a new Point with absolute coordinate values. If this is a DirectedPoint, dirY (in case this is a DirectedPoint3d and dirZ are copied unchanged.
      Specified by:
      abs in interface Point<Point2d>
      Overrides:
      abs in class Point2d
      Returns:
      a new point with absolute coordinate values
    • normalize

      public DirectedPoint2d normalize() throws DrawRuntimeException
      Description copied from interface: Point
      Return a new Point with a distance of 1 to the origin.
      Specified by:
      normalize in interface Point<Point2d>
      Overrides:
      normalize in class Point2d
      Returns:
      the normalized point
      Throws:
      DrawRuntimeException - when point is the origin, and no length can be established for scaling
    • interpolate

      public DirectedPoint2d interpolate(DirectedPoint2d otherPoint, double fraction)
      Interpolate towards another DirectedPoint2d with a fraction. It is allowed for fraction to be less than zero or larger than 1. In that case the interpolation turns into an extrapolation. DirZ is interpolated using the AngleUtil.interpolateShortest method.
      Parameters:
      otherPoint - the other point
      fraction - the factor for interpolation towards the other point. When <code>fraction</code> is between 0 and 1, it is an interpolation, otherwise an extrapolation. If fraction is 0; this Point is returned; if fraction is 1, the otherPoint is returned
      Returns:
      a new OrientedPoint2d at the requested fraction
      Throws:
      NullPointerException - when otherPoint is null
      ArithmeticException - when fraction is NaN
    • rotate

      public DirectedPoint2d rotate(double rotateZ)
      Return a new DirectedPoint2d with an in-place rotation around the z-axis by the provided rotateZ. The resulting rotation is normalized between -π and π.
      Parameters:
      rotateZ - the rotation around the z-axis
      Returns:
      a new point with the same coordinates and applied rotation
      Throws:
      ArithmeticException - when rotateZ is NaN
    • getDirZ

      public double getDirZ()
      Description copied from interface: Directed2d
      Retrieve the angle from the positive x-axis. Positive rotates towards the positive y-axis (and beyond).
      Specified by:
      getDirZ in interface Directed2d<DirectedPoint2d>
      Returns:
      dirZ
    • iterator

      public Iterator<Point2d> iterator()
      Specified by:
      iterator in interface Iterable<Point2d>
      Overrides:
      iterator in class Point2d
    • toString

      public String toString()
      Description copied from interface: Drawable
      Produce a string describing the Drawable using default conversion for the (double) coordinate values. Regrettably, it is not allowed to provide a default implementation here.
      Specified by:
      toString in interface Drawable<Point2d>
      Overrides:
      toString in class Point2d
      Returns:
      a string describing the Drawable
    • toString

      public String toString(String doubleFormat, boolean doNotIncludeClassName)
      Description copied from interface: Drawable
      Produce a String describing the Drawable.
      Specified by:
      toString in interface Drawable<Point2d>
      Overrides:
      toString in class Point2d
      Parameters:
      doubleFormat - a format string (something like "%6.3f") which will be used to render every coordinate value)
      doNotIncludeClassName - if true; the output of toString is not prefixed by the class name. This is useful for concatenating the textual representation of lots of Drawables (e.g. an array, or a List).
      Returns:
      textual representation of the Drawable
    • epsilonEquals

      public boolean epsilonEquals(DirectedPoint2d other, double epsilonCoordinate, double epsilonRotation) throws NullPointerException, IllegalArgumentException
      Description copied from interface: Directed
      Compare this Directed with another Directed with specified tolerances in the coordinates and the angles.
      Specified by:
      epsilonEquals in interface Directed<DirectedPoint2d>
      Parameters:
      other - the Directed to compare to
      epsilonCoordinate - the upper bound of difference for one of the coordinates; use Double.POSITIVE_INFINITY if you do not want to check the coordinates
      epsilonRotation - the upper bound of difference for the direction(s); use Double.POSITIVE_INFINITY if you do not want to check the angles
      Returns:
      boolean;true if x, y, and z are less than epsilonCoordinate apart, and rotX, rotY and rotZ are less than epsilonRotation apart, otherwise false
      Throws:
      NullPointerException - when other is null
      IllegalArgumentException - epsilonCoordinate or epsilonRotation is negative
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Point2d
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Point2d