Class HomogeneousPoint2D

java.lang.Object
com.irurueta.geometry.Point2D
com.irurueta.geometry.HomogeneousPoint2D
All Implemented Interfaces:
Point<Point2D>, Serializable

public class HomogeneousPoint2D extends Point2D implements Serializable
Subclass of Point2D defining an homogeneous 2D point. An homogeneous 2d point is defined by three coordinates: (x,y,w), where x and y are the horizontal and vertical coordinates, respectively, and w is a normalization (homogenization) factor. Homogeneous 2d points at infinity are expressed using w=0 (x,y,0) where (x,y) describe the direction of the 2d point towards infinity. Inhomogeneous 2d points can be transformed into homogeneous 2d points by setting the w coordinate to one (w=1, not at infinity) as follows: Inhomogeneous 2d point (x,y) -< Homogeneous 2d point (x,y,1).
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final double
    Default threshold to consider a point is located at infinity.
    private boolean
    Determines whether this point is already normalized.
    private static final double
    Machine precision.
    private double
    Defines the W coordinate of an homogeneous 2D point.
    private double
    Defines the X coordinate of an homogeneous 2D point.
    private double
    Defines the Y coordinate of an homogeneous 2D point.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty constructor.
    HomogeneousPoint2D(double[] v)
    Constructor of this class.
    HomogeneousPoint2D(double x, double y, double w)
    Constructor of this class.
    This constructor sets a new homogeneous 2D point using as initialization provided Point2D instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    double[]
    Returns an array containing the coordinates of this Point2D.
    void
    asArray(double[] array)
    Uses provided array to store the coordinates of this HomogeneousPoint2D
    boolean
    Checks if the homogeneous 2d point described by this instance equals the input HomogeneousPoint2d (using a comparison threshold).
    boolean
    equals(HomogeneousPoint2D point, double threshold)
    Checks if the homogeneous 2d point described by this instance equals the input HomogeneousPoint2d (using a comparison threshold).
    boolean
    Checks if the homogeneous 2d point described by this instance equals the input InhomogeneousPoint2d (using a comparison threshold).
    boolean
    equals(InhomogeneousPoint2D point, double threshold)
    Checks if the homogeneous 2d point described by this instance equals the input InhomogeneousPoint2d (using a comparison threshold).
    boolean
    equals(Point2D point, double threshold)
    Checks if the homogeneous 2d point described by this instance equals the input Point2D (using a comparison threshold).
    boolean
    Checks if provided object equals current 2D point.
    double
    Returns W homogeneous coordinate of this 2d point.
    double
    Returns X homogeneous coordinate of this 2d point.
    double
    Returns Y homogeneous coordinate of this 2d point.
    double
    Returns X inhomogeneous coordinate of this 2d point.
    double
    Returns Y inhomogeneous coordinate of this 2d point.
    Returns the type of coordinates used to represent a Point2D.
    double
    Returns the W coordinate of the given homogeneous 2D point instance.
    double
    Returns the X coordinate of the given homogeneous 2D point instance.
    double
    Returns the Y coordinate of the given homogeneous 2D point instance.
    int
    Returns hash code value.
    boolean
    Checks whether this Point2D is at infinity or not.
    boolean
    isAtInfinity(double threshold)
    Checks whether this homogeneous 2D point is at infinity or not.
    boolean
    Returns boolean indicating whether this point has already been mNormalized
    void
    Method to normalize a 2d point by dividing all homogeneous components by its norm.
    final void
    setCoordinates(double[] v)
    Sets the coordinates of a 2d point using an array containing its coordinates.
    void
    setCoordinates(double x, double y, double w)
    Sets the coordinates of this homogeneous 2D point by using provided X, Y and W coordinates.
    final void
    Sets coordinates of this instance using the coordinates of provided 2D point.
    void
    setHomogeneousCoordinates(double homX, double homY, double homW)
    Sets coordinates of this 2d point instance using provided homogeneous coordinates.
    void
    setInhomogeneousCoordinates(double inhomX, double inhomY)
    Sets coordinates of this 2d point instance using provided inhomogeneous coordinates.
    void
    setInhomX(double inhomX)
    Sets X inhomogeneous coordinate of this 2d point.
    void
    setInhomY(double inhomY)
    Sets Y inhomogeneous coordinate of this 2d point.
    void
    setW(double w)
    Sets the W coordinate of this homogeneous point.
    void
    setX(double x)
    Sets the X coordinate of this homogeneous point.
    void
    setY(double y)
    Sets the Y coordinate of this homogeneous point.
    Converts this instance into an inhomogeneous 2D point and returns the result as a new inhomogeneous 2D point instance.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_INFINITY_THRESHOLD

      private static final double DEFAULT_INFINITY_THRESHOLD
      Default threshold to consider a point is located at infinity.
      See Also:
    • PRECISION

      private static final double PRECISION
      Machine precision.
      See Also:
    • x

      private double x
      Defines the X coordinate of an homogeneous 2D point.
    • y

      private double y
      Defines the Y coordinate of an homogeneous 2D point.
    • w

      private double w
      Defines the W coordinate of an homogeneous 2D point.
    • normalized

      private boolean normalized
      Determines whether this point is already normalized.
  • Constructor Details

    • HomogeneousPoint2D

      public HomogeneousPoint2D()
      Empty constructor.
    • HomogeneousPoint2D

      public HomogeneousPoint2D(double[] v)
      Constructor of this class. This constructor sets a new homogeneous v array containing the coordinates X, Y and W of the given point.
      Parameters:
      v - Array of length 3 containing the 2D coordinates of an homogeneous point.
      Throws:
      IllegalArgumentException - Raised when the size of the array is different of 3.
    • HomogeneousPoint2D

      public HomogeneousPoint2D(double x, double y, double w)
      Constructor of this class. This constructor sets a new homogeneous 2D point using the coordinates X, Y and W of the given point.
      Parameters:
      x - X coordinate of the given 2D point.
      y - Y coordinate of the given 2D point.
      w - W coordinate of the given 2D point.
    • HomogeneousPoint2D

      public HomogeneousPoint2D(Point2D point)
      This constructor sets a new homogeneous 2D point using as initialization provided Point2D instance.
      Parameters:
      point - Point to initialize new instance to.
  • Method Details

    • getX

      public double getX()
      Returns the X coordinate of the given homogeneous 2D point instance.
      Returns:
      X coordinate.
    • setX

      public void setX(double x)
      Sets the X coordinate of this homogeneous point.
      Parameters:
      x - X coordinate.
    • getY

      public double getY()
      Returns the Y coordinate of the given homogeneous 2D point instance.
      Returns:
      Y coordinate.
    • setY

      public void setY(double y)
      Sets the Y coordinate of this homogeneous point.
      Parameters:
      y - Y coordinate.
    • getW

      public double getW()
      Returns the W coordinate of the given homogeneous 2D point instance.
      Returns:
      W coordinate.
    • setW

      public void setW(double w)
      Sets the W coordinate of this homogeneous point.
      Parameters:
      w - W coordinate.
    • setCoordinates

      public void setCoordinates(double x, double y, double w)
      Sets the coordinates of this homogeneous 2D point by using provided X, Y and W coordinates.
      Parameters:
      x - X coordinate.
      y - Y coordinate.
      w - W coordinate.
    • setCoordinates

      public final void setCoordinates(double[] v)
      Sets the coordinates of a 2d point using an array containing its coordinates.
      Specified by:
      setCoordinates in class Point2D
      Parameters:
      v - Array containing the coordinates of the point.
      Throws:
      IllegalArgumentException - Raised if provided array does not have a valid size.
    • setCoordinates

      public final void setCoordinates(Point2D point)
      Sets coordinates of this instance using the coordinates of provided 2D point.
      Specified by:
      setCoordinates in class Point2D
      Parameters:
      point - Input point.
    • getHomX

      public double getHomX()
      Returns X homogeneous coordinate of this 2d point.
      Specified by:
      getHomX in class Point2D
      Returns:
      X homogeneous coordinate.
    • getHomY

      public double getHomY()
      Returns Y homogeneous coordinate of this 2d point.
      Specified by:
      getHomY in class Point2D
      Returns:
      Y homogeneous coordinate.
    • getHomW

      public double getHomW()
      Returns W homogeneous coordinate of this 2d point.
      Specified by:
      getHomW in class Point2D
      Returns:
      W homogeneous coordinate.
    • setHomogeneousCoordinates

      public void setHomogeneousCoordinates(double homX, double homY, double homW)
      Sets coordinates of this 2d point instance using provided homogeneous coordinates.
      Specified by:
      setHomogeneousCoordinates in class Point2D
      Parameters:
      homX - x homogeneous coordinate.
      homY - y homogeneous coordinate.
      homW - w homogeneous coordinate.
    • getInhomX

      public double getInhomX()
      Returns X inhomogeneous coordinate of this 2d point.
      Specified by:
      getInhomX in class Point2D
      Returns:
      X inhomogeneous coordinate.
    • setInhomX

      public void setInhomX(double inhomX)
      Sets X inhomogeneous coordinate of this 2d point.
      Specified by:
      setInhomX in class Point2D
      Parameters:
      inhomX - inhomogeneous coordinate.
    • getInhomY

      public double getInhomY()
      Returns Y inhomogeneous coordinate of this 2d point.
      Specified by:
      getInhomY in class Point2D
      Returns:
      Y inhomogeneous coordinate.
    • setInhomY

      public void setInhomY(double inhomY)
      Sets Y inhomogeneous coordinate of this 2d point.
      Specified by:
      setInhomY in class Point2D
      Parameters:
      inhomY - Y inhomogeneous coordinate.
    • setInhomogeneousCoordinates

      public void setInhomogeneousCoordinates(double inhomX, double inhomY)
      Sets coordinates of this 2d point instance using provided inhomogeneous coordinates.
      Specified by:
      setInhomogeneousCoordinates in class Point2D
      Parameters:
      inhomX - x inhomogeneous coordinate.
      inhomY - y inhomogeneous coordinate.
    • equals

      public boolean equals(Object obj)
      Checks if provided object equals current 2D point.
      Overrides:
      equals in class Point2D
      Parameters:
      obj - Object to compare.
      Returns:
      True if both objects are considered to be equal, false otherwise.
    • hashCode

      public int hashCode()
      Returns hash code value.
      Specified by:
      hashCode in class Point2D
      Returns:
      Hash code value.
    • equals

      public boolean equals(Point2D point, double threshold)
      Checks if the homogeneous 2d point described by this instance equals the input Point2D (using a comparison threshold).
      Specified by:
      equals in class Point2D
      Parameters:
      point - Point that will be compared to.
      threshold - threshold grade of tolerance to determine whether the points are equal or not. It is used because due to machine precision, the values might not be exactly equal (if not provided DEFAULT_COMPARISON_THRESHOLD is used).
      Returns:
      True if current point and input point are the same, false otherwise.
      Throws:
      IllegalArgumentException - Raised if threshold is negative.
    • equals

      public boolean equals(HomogeneousPoint2D point, double threshold)
      Checks if the homogeneous 2d point described by this instance equals the input HomogeneousPoint2d (using a comparison threshold).
      Parameters:
      point - Point that will be compared to.
      threshold - threshold grade of tolerance to determine whether the points are equal or not. It is used because due to machine precision, the values might not be exactly equal (if not provided DEFAULT_COMPARISON_THRESHOLD is used).
      Returns:
      True if current point and input point are the same, false otherwise.
      Throws:
      IllegalArgumentException - Raised if threshold is negative.
    • equals

      public boolean equals(HomogeneousPoint2D point)
      Checks if the homogeneous 2d point described by this instance equals the input HomogeneousPoint2d (using a comparison threshold).
      Parameters:
      point - Point that will be compared to.
      Returns:
      True if current point and input point are the same, false otherwise.
    • equals

      public boolean equals(InhomogeneousPoint2D point, double threshold)
      Checks if the homogeneous 2d point described by this instance equals the input InhomogeneousPoint2d (using a comparison threshold).
      Parameters:
      point - Point that will be compared to.
      threshold - threshold grade of tolerance to determine whether the points are equal or not. It is used because due to machine precision, the values might not be exactly equal (if not provided DEFAULT_COMPARISON_THRESHOLD is used).
      Returns:
      True if current point and input point are the same, false otherwise.
      Throws:
      IllegalArgumentException - Raised if threshold is negative.
    • equals

      public boolean equals(InhomogeneousPoint2D point)
      Checks if the homogeneous 2d point described by this instance equals the input InhomogeneousPoint2d (using a comparison threshold).
      Parameters:
      point - Point that will be compared to.
      Returns:
      True if current point and input point are the same, false otherwise.
    • isAtInfinity

      public boolean isAtInfinity()
      Checks whether this Point2D is at infinity or not.
      Specified by:
      isAtInfinity in class Point2D
      Returns:
      True if the point is at infinity. False otherwise.
    • isAtInfinity

      public boolean isAtInfinity(double threshold)
      Checks whether this homogeneous 2D point is at infinity or not. An homogeneous 2D point is at infinity when W coordinates are equal or close to zero.
      Parameters:
      threshold - Grade of tolerance to determine whether the point is at infinity or not. It is used because due to machine precision, the values might not be exactly equal.
      Returns:
      True if point is at infinity, false otherwise.
      Throws:
      IllegalArgumentException - Raised if threshold is negative.
    • getType

      public CoordinatesType getType()
      Returns the type of coordinates used to represent a Point2D.
      Specified by:
      getType in class Point2D
      Returns:
      Type of coordinates of this 2d point.
    • normalize

      public void normalize()
      Method to normalize a 2d point by dividing all homogeneous components by its norm. This only applies to homogeneous 2d points, because they are defined up to scale.
      Overrides:
      normalize in class Point2D
    • isNormalized

      public boolean isNormalized()
      Returns boolean indicating whether this point has already been mNormalized
      Overrides:
      isNormalized in class Point2D
      Returns:
      True if mNormalized, false otherwise.
    • toInhomogeneous

      public InhomogeneousPoint2D toInhomogeneous()
      Converts this instance into an inhomogeneous 2D point and returns the result as a new inhomogeneous 2D point instance.
      Returns:
      Converts and returns this point as an inhomogeneous 2D point.
    • asArray

      public double[] asArray()
      Returns an array containing the coordinates of this Point2D.
      Specified by:
      asArray in class Point2D
      Returns:
      Array containing coordinates of this Point2D.
    • asArray

      public void asArray(double[] array)
      Uses provided array to store the coordinates of this HomogeneousPoint2D
      Specified by:
      asArray in class Point2D
      Parameters:
      array - Array where coordinates will be stored.
      Throws:
      IllegalArgumentException - Raised if length of array is not 3.