Package com.irurueta.geometry
Class Point3D
java.lang.Object
com.irurueta.geometry.Point3D
- All Implemented Interfaces:
Point<Point3D>,Serializable
- Direct Known Subclasses:
HomogeneousPoint3D,InhomogeneousPoint3D
Abstract class defining the base interface that all 3D points should have.
3D points describe points in a 3D space such as the Euclidean space. They can
be implemented either as homogeneous or inhomogeneous points.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefines the threshold used when comparing two values.static final CoordinatesTypeDefault type of coordinates.static final doubleConstant defining minimum threshold.static final intLength of homogeneous coordinates array.static final intLength of inhomogeneous coordinates array. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract double[]asArray()Returns an array containing the coordinates of this Point3D.abstract voidasArray(double[] array) Uses provided array to store the coordinates of this Point3Dstatic Point3Dcentroid(Collection<Point3D> points) Computes the centroid of provided collection of points by computing the mean of their inhomogeneous coordinates.static voidcentroid(Collection<Point3D> points, Point3D result) Computes the centroid of provided collection of points by computing the mean of their inhomogeneous coordinates.static Point3Dcreate()Creates and returns an instance of an existing subclass of Point3D using DEFAULT_COORDINATES_TYPE.static Point3Dcreate(double[] v) Creates and returns an instance of any existing subclass of Point3D depending on provided vector length.static Point3Dcreate(CoordinatesType coordinatesType) Creates and returns an instance of any existing subclass of Point3D specified in coordinatesType.static Point3Dcreate(CoordinatesType coordinatesType, double[] v) Creates and returns an instance of any existing subclass of Point3D specified in coordinatesType.doubledistanceTo(Point3D point) Returns Euclidean distance between this point and provided point.doubledotProduct(Point3D point) Computes the dot product between the homogeneous coordinates x, y, z, w of this point and the ones of provided point.booleanChecks if the 3D point described by this class equals the input Point3D (using DEFAULT_COMPARISON_THRESHOLD).abstract booleanChecks if the 3D point described by this class equals the input Point3D (using a comparison threshold).booleanChecks if provided object equals current 3D point.intReturns number of dimensions of this point implementation.abstract doublegetHomW()Returns W homogeneous coordinate of this 3D point.abstract doublegetHomX()Returns X homogeneous coordinate of this 3D point.abstract doublegetHomY()Returns Y homogeneous coordinate of this 3D point.abstract doublegetHomZ()Returns Z homogeneous coordinate of this 3D point.doublegetInhomogeneousCoordinate(int dim) Gets value of inhomogeneous coordinate for provided dimension.abstract doubleReturns X inhomogeneous coordinate of this 3D point.abstract doubleReturns Y inhomogeneous coordinate of this 3D point.abstract doubleReturns Z inhomogeneous coordinate of this 3D point.abstract CoordinatesTypegetType()Returns the type of coordinates used to represent a Point3D.abstract inthashCode()Returns hash code value.abstract booleanChecks whether this Point3D is at infinity or not.booleanReturns true if this point is between points point1 and point2, in other words, is inside the segment formed by those 2 points.booleanReturns true if this point is between points point1 and point2, in other words, is inside the segment formed by those 2 points.booleanReturns boolean indicating whether this point has already been normalized.voidMethod to normalize a 3D point.abstract voidsetCoordinates(double[] v) Sets the coordinates of a 3D point using an array containing its coordinates.abstract voidsetCoordinates(Point3D point) Sets coordinates of this instance using the coordinates of provided 3D point.abstract voidsetHomogeneousCoordinates(double homX, double homY, double homZ, double homW) Sets coordinates of this 3D point instance using provided homogeneous coordinates.voidsetInhomogeneousCoordinate(int dim, double value) Sets value of inhomogeneous coordinate for provided dimension.abstract voidsetInhomogeneousCoordinates(double inhomX, double inhomY, double inhomZ) Sets coordinates of this 3D point instance using provided inhomogeneous coordinates.abstract voidsetInhomX(double inhomX) Sets X inhomogeneous coordinate of this 3D point.abstract voidsetInhomY(double inhomY) Sets Y inhomogeneous coordinate of this 3D point.abstract voidsetInhomZ(double inhomZ) Sets Z inhomogeneous coordinate of this 3D point.doublesqrDistanceTo(Point3D point) Returns squared Euclidean distance between this point and provided point.
-
Field Details
-
DEFAULT_COMPARISON_THRESHOLD
public static final double DEFAULT_COMPARISON_THRESHOLDDefines the threshold used when comparing two values.- See Also:
-
MIN_THRESHOLD
public static final double MIN_THRESHOLDConstant defining minimum threshold.- See Also:
-
POINT3D_HOMOGENEOUS_COORDINATES_LENGTH
public static final int POINT3D_HOMOGENEOUS_COORDINATES_LENGTHLength of homogeneous coordinates array.- See Also:
-
POINT3D_INHOMOGENEOUS_COORDINATES_LENGTH
public static final int POINT3D_INHOMOGENEOUS_COORDINATES_LENGTHLength of inhomogeneous coordinates array.- See Also:
-
DEFAULT_COORDINATES_TYPE
Default type of coordinates.
-
-
Constructor Details
-
Point3D
protected Point3D()Constructor of this class.
-
-
Method Details
-
create
Creates and returns an instance of any existing subclass of Point3D 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 3D homogeneous or inhomogeneous point.- Returns:
- Created Point3D.
- Throws:
IllegalArgumentException- Raised if the size of provided array is not valid.
-
create
Creates and returns an instance of any existing subclass of Point3D depending on provided vector length. Size of provided vector is also checked to ensure it has appropriate size to represent 3D points either using inhomogeneous or homogeneous coordinates.- Parameters:
v- Array containing the coordinates of the 3D homogeneous or inhomogeneous 3D point.- Returns:
- Created Point3D.
- Throws:
IllegalArgumentException- Raised if the size of provided array is not valid.
-
create
Creates and returns an instance of any existing subclass of Point3D specified in coordinatesType.- Parameters:
coordinatesType- Type of coordinates used.- Returns:
- Created Point3D.
-
create
Creates and returns an instance of an existing subclass of Point3D using DEFAULT_COORDINATES_TYPE.- Returns:
- Create Point3D.
-
asArray
public abstract double[] asArray()Returns an array containing the coordinates of this Point3D.- Returns:
- Array containing coordinates of this Point3D.
-
asArray
public abstract void asArray(double[] array) Uses provided array to store the coordinates of this Point3D- 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 3D 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
Sets coordinates of this instance using the coordinates of provided 3D point.- Parameters:
point- Input point.
-
getHomX
public abstract double getHomX()Returns X homogeneous coordinate of this 3D point.- Returns:
- X homogeneous coordinate.
-
getHomY
public abstract double getHomY()Returns Y homogeneous coordinate of this 3D point.- Returns:
- Y homogeneous coordinate.
-
getHomZ
public abstract double getHomZ()Returns Z homogeneous coordinate of this 3D point.- Returns:
- Z homogeneous coordinate.
-
getHomW
public abstract double getHomW()Returns W homogeneous coordinate of this 3D point.- Returns:
- W homogeneous coordinate.
-
setHomogeneousCoordinates
public abstract void setHomogeneousCoordinates(double homX, double homY, double homZ, double homW) Sets coordinates of this 3D point instance using provided homogeneous coordinates.- Parameters:
homX- x homogeneous coordinate.homY- y homogeneous coordinate.homZ- z homogeneous coordinate.homW- w homogeneous coordinate.
-
getInhomX
public abstract double getInhomX()Returns X inhomogeneous coordinate of this 3D point.- Returns:
- X inhomogeneous coordinate.
-
setInhomX
public abstract void setInhomX(double inhomX) Sets X inhomogeneous coordinate of this 3D point.- Parameters:
inhomX- X inhomogeneous coordinate.
-
getInhomY
public abstract double getInhomY()Returns Y inhomogeneous coordinate of this 3D point.- Returns:
- Y inhomogeneous coordinate.
-
setInhomY
public abstract void setInhomY(double inhomY) Sets Y inhomogeneous coordinate of this 3D point.- Parameters:
inhomY- Y inhomogeneous coordinate.
-
getInhomZ
public abstract double getInhomZ()Returns Z inhomogeneous coordinate of this 3D point.- Returns:
- Z inhomogeneous coordinate.
-
setInhomZ
public abstract void setInhomZ(double inhomZ) Sets Z inhomogeneous coordinate of this 3D point.- Parameters:
inhomZ- Z inhomogeneous coordinate.
-
setInhomogeneousCoordinates
public abstract void setInhomogeneousCoordinates(double inhomX, double inhomY, double inhomZ) Sets coordinates of this 3D point instance using provided inhomogeneous coordinates.- Parameters:
inhomX- x inhomogeneous coordinate.inhomY- y inhomogeneous coordinate.inhomZ- z inhomogeneous coordinate.
-
equals
Checks if the 3D point described by this class equals the input Point3D (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
Checks if the 3D point described by this class equals the input Point3D (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
Checks if provided object equals current 3D point. -
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. -
isAtInfinity
public abstract boolean isAtInfinity()Checks whether this Point3D is at infinity or not.- Returns:
- True if the point is at infinity. False otherwise.
-
getType
Returns the type of coordinates used to represent a Point3D.- Returns:
- Type of coordinates of this 2d point.
-
normalize
public void normalize()Method to normalize a 3D 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:
getDimensionsin interfacePoint<Point3D>- Returns:
- number of dimensions.
-
getInhomogeneousCoordinate
public double getInhomogeneousCoordinate(int dim) Gets value of inhomogeneous coordinate for provided dimension.- Specified by:
getInhomogeneousCoordinatein interfacePoint<Point3D>- 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:
setInhomogeneousCoordinatein interfacePoint<Point3D>- 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
Returns Euclidean distance between this point and provided point.- Specified by:
distanceToin interfacePoint<Point3D>- Parameters:
point- Point to compare.- Returns:
- Euclidean distance between this point and provided point.
-
sqrDistanceTo
Returns squared Euclidean distance between this point and provided point.- Specified by:
sqrDistanceToin interfacePoint<Point3D>- Parameters:
point- point to compare.- Returns:
- Euclidean distance between this point and provided point.
-
dotProduct
Computes the dot product between the homogeneous coordinates x, y, z, w of this point and the ones of provided point.- Parameters:
point- point to compute dot product with.- Returns:
- dot product value.
-
isBetween
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
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.
-
centroid
Computes the centroid of provided collection of points by computing the mean of their inhomogeneous coordinates.- Parameters:
points- collection of points to compute centroid from.result- instance where computed centroid will be stored.
-
centroid
Computes the centroid of provided collection of points by computing the mean of their inhomogeneous coordinates.- Parameters:
points- collection of points to compute centroid from.- Returns:
- computed centroid.
-