Class Point2D

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

public abstract class Point2D extends Object implements Serializable, Point<Point2D>
Abstract class defining the base interface that all 2D points should have. 2D points describe points in a 2D space such as images. They can be implemented either as homogeneous or inhomogeneous points.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Defines the threshold used when comparing two values.
    static final CoordinatesType
    Default type of coordinates.
    static final double
    Constant defining minimum threshold.
    static final int
    Length of homogeneous coordinates array.
    static final int
    Length of inhomogeneous coordinates array.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor of this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract double[]
    Returns an array containing the coordinates of this Point2D.
    abstract void
    asArray(double[] array)
    Uses provided array to store the coordinates of this Point2D.
    static Point2D
    Creates and returns an instance of an existing subclass of Point2D using DEFAULT_COORDINATES_TYPE.
    static Point2D
    create(double[] v)
    Creates and returns an instance of any existing subclass of Point2D depending on provided vector length.
    static Point2D
    create(CoordinatesType coordinatesType)
    Creates and returns an instance of any existing subclass of Point2D specified in coordinatesType.
    static Point2D
    create(CoordinatesType coordinatesType, double[] v)
    Creates and returns an instance of any existing subclass of Point2D specified in coordinatesType.
    double
    Returns Euclidean distance between this point and provided point.
    double
    Computes the dot product between the homogeneous coordinates x, y,w of this point and the ones of provided point.
    boolean
    equals(Point2D point)
    Checks if the 2d point described by this class equals the input Point2D (using DEFAULT_COMPARISON_THRESHOLD).
    abstract boolean
    equals(Point2D point, double threshold)
    Checks if the 2d point described by this class equals the input Point2D (using a comparison threshold).
    boolean
    Checks if provided object equals current 2d point.
    int
    Returns number of dimensions of this point implementation.
    abstract double
    Returns W homogeneous coordinate of this 2d point.
    abstract double
    Returns X homogeneous coordinate of this 2d point.
    abstract double
    Returns Y homogeneous coordinate of this 2d point.
    double
    Gets value of inhomogeneous coordinate for provided dimension.
    abstract double
    Returns X inhomogeneous coordinate of this 2d point.
    abstract double
    Returns Y inhomogeneous coordinate of this 2d point.
    Returns the type of coordinates used to represent a Point2D.
    abstract int
    Returns hash code value.
    abstract boolean
    Checks whether this Point2D is at infinity or not.
    boolean
    isBetween(Point2D point1, Point2D point2)
    Returns true if this point is between points point1 and point2, in other words, is inside the segment formed by those 2 points.
    boolean
    isBetween(Point2D point1, Point2D point2, double threshold)
    Returns true if this point is between points point1 and point2, in other words, is inside the segment formed by those 2 points.
    boolean
    Returns boolean indicating whether this point has already been normalized.
    void
    Method to normalize a 2d point.
    abstract void
    setCoordinates(double[] v)
    Sets the coordinates of a 2d point using an array containing its coordinates.
    abstract void
    Sets coordinates of this instance using the coordinates of provided 2D point.
    abstract void
    setHomogeneousCoordinates(double homX, double homY, double homW)
    Sets coordinates of this 2d point instance using provided homogeneous coordinates.
    void
    setInhomogeneousCoordinate(int dim, double value)
    Sets value of inhomogeneous coordinate for provided dimension.
    abstract void
    setInhomogeneousCoordinates(double inhomX, double inhomY)
    Sets coordinates of this 2d point instance using provided inhomogeneous coordinates.
    abstract void
    setInhomX(double inhomX)
    Sets X inhomogeneous coordinate of this 2d point.
    abstract void
    setInhomY(double inhomY)
    Sets Y inhomogeneous coordinate of this 2d point.
    double
    Returns squared Euclidean distance between this point and provided point.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_COMPARISON_THRESHOLD

      public static final double DEFAULT_COMPARISON_THRESHOLD
      Defines the threshold used when comparing two values.
      See Also:
    • MIN_THRESHOLD

      public static final double MIN_THRESHOLD
      Constant defining minimum threshold.
      See Also:
    • POINT2D_HOMOGENEOUS_COORDINATES_LENGTH

      public static final int POINT2D_HOMOGENEOUS_COORDINATES_LENGTH
      Length of homogeneous coordinates array.
      See Also:
    • POINT2D_INHOMOGENEOUS_COORDINATES_LENGTH

      public static final int POINT2D_INHOMOGENEOUS_COORDINATES_LENGTH
      Length of inhomogeneous coordinates array.
      See Also:
    • DEFAULT_COORDINATES_TYPE

      public static final CoordinatesType DEFAULT_COORDINATES_TYPE
      Default type of coordinates.
  • Constructor Details

    • Point2D

      protected Point2D()
      Constructor of this class.
  • Method Details

    • create

      public static Point2D create(CoordinatesType coordinatesType, double[] v)
      Creates and returns an instance of any existing subclass of Point2D specified in coordinatesType. The right size of the provided array is also checked depending on the type of coordinates used.
      Parameters:
      coordinatesType - Type of coordinates used.
      v - Array containing the coordinates of the 2d homogeneous or inhomogeneous point.
      Returns:
      Created Point2D.
      Throws:
      IllegalArgumentException - Raised if the size of provided array is not valid.
    • create

      public static Point2D create(double[] v)
      Creates and returns an instance of any existing subclass of Point2D depending on provided vector length. Size of provided vector is also checked to ensure it has appropriate size to represent 2d points either using inhomogeneous or homogeneous coordinates.
      Parameters:
      v - Array containing the coordinates of the 2D homogeneous or inhomogeneous 2d point.
      Returns:
      Created Point2D.
      Throws:
      IllegalArgumentException - Raised if the size of provided array is not valid.
    • create

      public static Point2D create(CoordinatesType coordinatesType)
      Creates and returns an instance of any existing subclass of Point2D specified in coordinatesType.
      Parameters:
      coordinatesType - Type of coordinates used.
      Returns:
      Created Point2D.
    • create

      public static Point2D create()
      Creates and returns an instance of an existing subclass of Point2D using DEFAULT_COORDINATES_TYPE.
      Returns:
      Create Point2D.
    • asArray

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

      public abstract void asArray(double[] array)
      Uses provided array to store the coordinates of this Point2D.
      Parameters:
      array - Array where coordinates will be stored.
      Throws:
      IllegalArgumentException - Raised if length of array is not valid.
    • setCoordinates

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

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

      public abstract double getHomX()
      Returns X homogeneous coordinate of this 2d point.
      Returns:
      X homogeneous coordinate.
    • getHomY

      public abstract double getHomY()
      Returns Y homogeneous coordinate of this 2d point.
      Returns:
      Y homogeneous coordinate.
    • getHomW

      public abstract double getHomW()
      Returns W homogeneous coordinate of this 2d point.
      Returns:
      W homogeneous coordinate.
    • setHomogeneousCoordinates

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

      public abstract double getInhomX()
      Returns X inhomogeneous coordinate of this 2d point.
      Returns:
      X inhomogeneous coordinate.
    • setInhomX

      public abstract void setInhomX(double inhomX)
      Sets X inhomogeneous coordinate of this 2d point.
      Parameters:
      inhomX - X inhomogeneous coordinate.
    • getInhomY

      public abstract double getInhomY()
      Returns Y inhomogeneous coordinate of this 2d point.
      Returns:
      Y inhomogeneous coordinate.
    • setInhomY

      public abstract void setInhomY(double inhomY)
      Sets Y inhomogeneous coordinate of this 2d point.
      Parameters:
      inhomY - Y inhomogeneous coordinate.
    • setInhomogeneousCoordinates

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

      public abstract boolean equals(Point2D point, double threshold)
      Checks if the 2d point described by this class equals the input Point2D (using a comparison threshold).
      Parameters:
      point - Point that will be compared to.
      threshold - threshold used to check that the difference of the values is close to zero with an absolute error defined by threshold.
      Returns:
      True if current point and input point are the same, false otherwise.
      Throws:
      IllegalArgumentException - Raised if threshold is negative.
    • equals

      public boolean equals(Point2D point)
      Checks if the 2d point described by this class equals the input Point2D (using DEFAULT_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(Object obj)
      Checks if provided object equals current 2d point.
      Overrides:
      equals in class Object
      Parameters:
      obj - Object to compare.
      Returns:
      True if both objects are considered to be equal, false otherwise.
    • hashCode

      public abstract int hashCode()
      Returns hash code value. This is only defined to keep the compiler happy. This method must be overridden in subclasses of this class.
      Overrides:
      hashCode in class Object
      Returns:
      Hash code.
    • isAtInfinity

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

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

      public void normalize()
      Method to normalize a 2d point. This only applies to homogeneous 2d points, otherwise it has no effect. This method is meant to be overridden.
    • isNormalized

      public boolean isNormalized()
      Returns boolean indicating whether this point has already been normalized. This method is meant to be overridden. By default, it will always return true, to indicate that no further normalization is possible.
      Returns:
      True if normalized, false otherwise.
    • getDimensions

      public int getDimensions()
      Returns number of dimensions of this point implementation.
      Specified by:
      getDimensions in interface Point<Point2D>
      Returns:
      number of dimensions.
    • getInhomogeneousCoordinate

      public double getInhomogeneousCoordinate(int dim)
      Gets value of inhomogeneous coordinate for provided dimension.
      Specified by:
      getInhomogeneousCoordinate in interface Point<Point2D>
      Parameters:
      dim - dimension to retrieve coordinate for (i.e. 0 means x, 1 means y, 2 means z, etc).
      Returns:
      value of inhomogeneous coordinate.
      Throws:
      IllegalArgumentException - if provided dimension value is negative or exceeds number of dimensions.
    • setInhomogeneousCoordinate

      public void setInhomogeneousCoordinate(int dim, double value)
      Sets value of inhomogeneous coordinate for provided dimension.
      Specified by:
      setInhomogeneousCoordinate in interface Point<Point2D>
      Parameters:
      dim - dimension to set coordinate for (i.e. 0 means x, 1 means y, 2 means z, etc.).
      value - value to be set.
      Throws:
      IllegalArgumentException - if provided dimension value is negative or exceeds number of dimensions.
    • distanceTo

      public double distanceTo(Point2D point)
      Returns Euclidean distance between this point and provided point.
      Specified by:
      distanceTo in interface Point<Point2D>
      Parameters:
      point - Point to compare.
      Returns:
      Euclidean distance between this point and provided point.
    • sqrDistanceTo

      public double sqrDistanceTo(Point2D point)
      Returns squared Euclidean distance between this point and provided point.
      Specified by:
      sqrDistanceTo in interface Point<Point2D>
      Parameters:
      point - point to compare.
      Returns:
      Euclidean distance between this point and provided point.
    • dotProduct

      public double dotProduct(Point2D point)
      Computes the dot product between the homogeneous coordinates x, y,w of this point and the ones of provided point.
      Parameters:
      point - point to compute dot product with.
      Returns:
      dot product value.
    • isBetween

      public boolean isBetween(Point2D point1, Point2D point2)
      Returns true if this point is between points point1 and point2, in other words, is inside the segment formed by those 2 points.
      Parameters:
      point1 - Point 1.
      point2 - Point 2.
      Returns:
      True if point is between point1 and point2, false otherwise.
    • isBetween

      public boolean isBetween(Point2D point1, Point2D point2, double threshold)
      Returns true if this point is between points point1 and point2, in other words, is inside the segment formed by those 2 points.
      Parameters:
      point1 - Point 1.
      point2 - Point 2.
      threshold - Threshold to determine if point is between.
      Returns:
      True if point is between point1 and point2, false otherwise.