Class Point2DSupport

java.lang.Object
edu.cnu.mdi.util.Point2DSupport

public final class Point2DSupport extends Object
Static operations on two-dimensional points interpreted as vectors.
  • Method Details

    • pointDelta

      public static Point2D.Double pointDelta(Point2D.Double wp1, Point2D.Double wp2)
      This is creation by subtraction. Be very careful of the order. This return wp2 - wp1
      Parameters:
      wp1 - the first point
      wp2 - the second point
      Returns:
      the delta, wp2-wp1
    • length

      public static double length(Point2D.Double wp)
      The length of the vector
      Parameters:
      wp - the point in question
      Returns:
      the usual vector magnitude
    • lengthSquare

      public static double lengthSquare(Point2D.Double wp)
      The length squared of the vector. This can be usefor for faster sorting.
      Parameters:
      wp - the point in question
      Returns:
      the square of the usual vector magnitude
    • unitVector

      public static Point2D.Double unitVector(Point2D.Double wp)
      Obtain a unit vector in the same direction as this vector
      Parameters:
      wp - the point in question
      Returns:
      a unit vector in the same direction as this vector
    • dot

      public static double dot(Point2D.Double v1, Point2D.Double v2)
      Usual inner product
      Parameters:
      v1 - one vector
      v2 - another vector
      Returns:
      the dot product
    • cross

      public static double cross(Point2D.Double v1, Point2D.Double v2)
      Get the magnitude of the cross product. The sign tells us whether we are in +z or -z direction.
      Parameters:
      v1 - one vector
      v2 - another vector
      Returns:
      the magnitude of the cross product
    • angleBetween

      public static double angleBetween(Point2D.Double v1, Point2D.Double v2)
      Get the angle between two vectors
      Parameters:
      v1 - one vector
      v2 - another vector
      Returns:
      the angle between the vectors in degrees.
    • project

      public static Point2D.Double project(Point2D.Double v, Point2D.Double a)
      Project one vector onto another vector
      Parameters:
      v - the vector being projected
      a - the vector defining the projection direction.
      Returns:
      the result of projecting v in the direction of a.
    • angle

      public static double angle(Point2D.Double wp)
      Get the polar coordinate angle.
      Parameters:
      wp - vector to inspect
      Returns:
      the angle, in degrees, measured ccw from the x axis.
    • distance

      public static double distance(Point2D.Double wp0, Point2D.Double wp1)
      Get the distance between two world points.
      Parameters:
      wp0 - the first world point.
      wp1 - the second world point.
      Returns:
      the distance between the two world points.
    • azimuth

      public static double azimuth(Point2D.Double wp0, Point2D.Double wp1)
      Computes the azimuth from this world point to another. The azimuth is the angle, in degrees, measured clockwise from north (the positive y axis) to the line connecting the two points.

      Unlike a normalized compass bearing, the result is not restricted to [0, 360) — it is derived directly from Math.atan2(double, double) and can be negative (e.g. a westward vector returns -90, not 270). Callers that need a normalized [0, 360) sweep should use AngleSupport.ccwSweepDeg(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double) or equivalent instead.

      Parameters:
      wp0 - the starting world point.
      wp1 - the ending world point.
      Returns:
      the azimuth from wp0 to wp1, in degrees; not normalized to [0, 360)
    • toString

      public static String toString(Point2D.Double wp)
      Get a string representation.
      Parameters:
      wp - point to format
      Returns:
      a string representation.