Package com.esri.core.geometry
Class Point2D
- java.lang.Object
-
- com.esri.core.geometry.Point2D
-
- All Implemented Interfaces:
Serializable
public class Point2D extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Point2D.CompareVectors
-
Field Summary
Fields Modifier and Type Field Description static int
dimensions
The number of components in the 2D point.double
x
double
y
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(Point2D other)
void
add(Point2D p1, Point2D p2)
int
compare(Point2D other)
static int
compareVectors(Point2D v1, Point2D v2)
Assume vector v_1 and v_2 have same origin.int
compareX(Point2D other)
Compares two vertices lexicographically by x.static int
compareZOrder(double x1, double y1, double x2, double y2)
Compares two points spatially using z-order.static int
compareZOrder(Point2D pt1, Point2D pt2)
Compares two points spatially using z-order.static Point2D
construct(double x, double y)
static double
crossProduct(double x1, double y1, double x2, double y2)
double
crossProduct(Point2D other)
static double
distance(Point2D pt1, Point2D pt2)
void
div(double f)
static double
dotProduct(double x1, double y1, double x2, double y2)
double
dotProduct(Point2D other)
boolean
equals(Point2D other)
boolean
equals(Object other)
double
get(int i)
Accesses the point components by index.double
getAxis(int ordinate)
Deprecated.static double
getClosestCoordinate(Point2D start_point, Point2D end_point, Point2D point_of_interest, boolean extrapolate)
Finds closest coordinate to a straight line defined by two endpoints and returns the interpolation factor.int
getQuarter()
int
hashCode()
static int
inCircleRobust(Point2D p, Point2D q, Point2D r, Point2D s)
Calculates if the point s is inside of the circumcircle inscribed by the clockwise oriented triangle p-q-r.void
interpolate(Point2D other, double alpha)
Performs linear interpolation between this and another point and assigns the result to this point.void
interpolate(Point2D p1, Point2D p2, double alpha)
Performs linear interpolation between p1 and p2 and assigns the result to this point.boolean
isEqual(double[] coord, double tol)
boolean
isEqual(double x_, double y_)
boolean
isEqual(Point2D other)
boolean
isEqual(Point2D other, double tol)
boolean
isFinite()
Checks if the point is finite.boolean
isNaN()
boolean
isZero()
void
leftPerpendicular()
void
leftPerpendicular(Point2D pt)
double
length()
static void
lerp(Point2D startPoint, Point2D endPoint, double t, Point2D dst)
Performs linear interpolation of two points in a consistent way (the result point is guaranteed to be between the start_point and end_point).void
negate()
void
negate(Point2D other)
double
norm(int metric)
Returns norm of the vector for a given metricvoid
normalize()
void
normalize(Point2D other)
double
offset(Point2D pt1, Point2D pt2)
Returns signed distance of this point from infinite line represented by pt_1...pt_2.static int
orientationNonRobust(Point2D p, Point2D q, Point2D r)
Calculates the orientation of the triangle formed by p->q->r, using simple cross product.static int
orientationRobust(Point2D p, Point2D q, Point2D r)
Calculates the orientation of the triangle formed by p->q->r.void
queryCoords(double[] pair)
void
rightPerpendicular()
void
rightPerpendicular(Point2D pt)
void
rotateDirect(double Cos, double Sin)
void
rotateReverse(double Cos, double Sin)
void
scale(double f)
Calculates this = this * fvoid
scale(double f, Point2D other)
Calculates this = other * fvoid
scaleAdd(double f, Point2D shift)
Calculates this = this * f + shiftvoid
scaleAdd(double f, Point2D other, Point2D shift)
Calculates this = other * f + shiftvoid
set(int i, double v)
Sets the point components by index.void
setCoords(double[] pair)
void
setCoords(double x, double y)
void
setCoords(Point2D other)
void
setNaN()
static double
sqrDistance(double x1, double y1, double x2, double y2)
static double
sqrDistance(Point2D pt1, Point2D pt2)
double
sqrLength()
void
sub(Point2D other)
void
sub(Point2D p1, Point2D p2)
String
toString()
-
-
-
Field Detail
-
x
public double x
-
y
public double y
-
dimensions
public static final int dimensions
The number of components in the 2D point. Always 2.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Point2D
public Point2D()
-
Point2D
public Point2D(double x, double y)
-
Point2D
public Point2D(Point2D other)
-
-
Method Detail
-
construct
public static Point2D construct(double x, double y)
-
setCoords
public void setCoords(double x, double y)
-
setCoords
public void setCoords(Point2D other)
-
setCoords
public void setCoords(double[] pair)
-
queryCoords
public void queryCoords(double[] pair)
-
isEqual
public boolean isEqual(Point2D other)
-
isEqual
public boolean isEqual(double x_, double y_)
-
isEqual
public boolean isEqual(Point2D other, double tol)
-
isEqual
public boolean isEqual(double[] coord, double tol)
-
equals
public boolean equals(Point2D other)
-
sub
public void sub(Point2D other)
-
add
public void add(Point2D other)
-
negate
public void negate()
-
negate
public void negate(Point2D other)
-
interpolate
public void interpolate(Point2D other, double alpha)
Performs linear interpolation between this and another point and assigns the result to this point. The result point is guaranteed to be between the input points, when alpha is between 0 and 1.- Parameters:
other
- another point of interpolation.alpha
- the interpolation factor. Same as lerp(this, other, alpha, this).
-
interpolate
public void interpolate(Point2D p1, Point2D p2, double alpha)
Performs linear interpolation between p1 and p2 and assigns the result to this point. The result point is guaranteed to be between the input points, when alpha is between 0 and 1.- Parameters:
p1
- start point of interpolation.p2
- end point of interpolation.alpha
- the interpolation factor. Same as lerp(p1, p2, alpha, this).
-
lerp
public static void lerp(Point2D startPoint, Point2D endPoint, double t, Point2D dst)
Performs linear interpolation of two points in a consistent way (the result point is guaranteed to be between the start_point and end_point).- Parameters:
startPoint
- start point of interpolation.endPoint
- end point of interpolation.t
- the interpolation factor. Value of 0 corresponds to start_point and value of 1 to the end_point.dst
- result of the interpolation.
-
scaleAdd
public void scaleAdd(double f, Point2D shift)
Calculates this = this * f + shift- Parameters:
f
-shift
-
-
scaleAdd
public void scaleAdd(double f, Point2D other, Point2D shift)
Calculates this = other * f + shift- Parameters:
f
-other
-shift
-
-
scale
public void scale(double f, Point2D other)
Calculates this = other * f- Parameters:
f
-other
-
-
scale
public void scale(double f)
Calculates this = this * f- Parameters:
f
-
-
div
public void div(double f)
-
compare
public int compare(Point2D other)
-
compareX
public int compareX(Point2D other)
Compares two vertices lexicographically by x.
-
normalize
public void normalize(Point2D other)
-
normalize
public void normalize()
-
length
public double length()
-
sqrLength
public double sqrLength()
-
dotProduct
public double dotProduct(Point2D other)
-
dotProduct
public static double dotProduct(double x1, double y1, double x2, double y2)
-
crossProduct
public double crossProduct(Point2D other)
-
crossProduct
public static double crossProduct(double x1, double y1, double x2, double y2)
-
rotateDirect
public void rotateDirect(double Cos, double Sin)
-
rotateReverse
public void rotateReverse(double Cos, double Sin)
-
leftPerpendicular
public void leftPerpendicular()
-
leftPerpendicular
public void leftPerpendicular(Point2D pt)
-
rightPerpendicular
public void rightPerpendicular()
-
rightPerpendicular
public void rightPerpendicular(Point2D pt)
-
isFinite
public boolean isFinite()
Checks if the point is finite.- Returns:
- true if x and y are finite values.
-
getQuarter
public int getQuarter()
-
compareVectors
public static int compareVectors(Point2D v1, Point2D v2)
Assume vector v_1 and v_2 have same origin. The function compares the vectors by the angle (the angle between the x axis and the vector in the counter clockwise direction). > > \ / V3 \ / V1 ----------------/-------------------->x In this example, _CompareVectors(V1, V2) == -1. \ _CompareVectors(V1, V3) == -1 \ V2 _CompareVectors(V2, V3) == 1 > Note: the method assumes that the vectors are of non-zero length.
-
sqrDistance
public static double sqrDistance(double x1, double y1, double x2, double y2)
-
setNaN
public void setNaN()
-
isNaN
public boolean isNaN()
-
isZero
public boolean isZero()
-
norm
public double norm(int metric)
Returns norm of the vector for a given metric- Parameters:
metric
- A value between 0 and 2 inclusive.- Returns:
- Returns the following: When metric is 0 returns max(abs(x), abs(y)), when metric is 1 - Manhattan metric abs(x) + abs(y), when metric is 2 - Euclidian metric: length()
-
offset
public double offset(Point2D pt1, Point2D pt2)
Returns signed distance of this point from infinite line represented by pt_1...pt_2. The returned distance is positive if this point lies on the right-hand side of the line, negative otherwise. If the two input points are equal, the (positive) distance of this point to p_1 is returned.
-
orientationNonRobust
public static int orientationNonRobust(Point2D p, Point2D q, Point2D r)
Calculates the orientation of the triangle formed by p->q->r, using simple cross product. Returns 1 for counter-clockwise, -1 for clockwise, and 0 for co-linear. Prone to roundoff errors, but fastest.
-
orientationRobust
public static int orientationRobust(Point2D p, Point2D q, Point2D r)
Calculates the orientation of the triangle formed by p->q->r. Returns 1 for counter-clockwise, -1 for clockwise, and 0 for co-linear. May use high precision arithmetics for some special degenerate cases.
-
inCircleRobust
public static int inCircleRobust(Point2D p, Point2D q, Point2D r, Point2D s)
Calculates if the point s is inside of the circumcircle inscribed by the clockwise oriented triangle p-q-r. Returns 1 for outside, -1 for inside, and 0 for cocircular. Note that the convention used here differs from what is commonly found in literature, which can define the relation in terms of a counter-clockwise oriented circle, and this flips the sign (think of the signed volume of the tetrahedron). May use high precision arithmetics for some special cases.
-
getAxis
@Deprecated public double getAxis(int ordinate)
Deprecated.Deprecated. Use get(i) method instead
-
get
public double get(int i)
Accesses the point components by index.- Parameters:
i
- The component index.- Returns:
- get(0) returns x, and get(1) returns y.
-
set
public void set(int i, double v)
Sets the point components by index.- Parameters:
i
- The component index. 0 means x, 1 means y.v
- The value to set.
-
compareZOrder
public static int compareZOrder(double x1, double y1, double x2, double y2)
Compares two points spatially using z-order. The method can be used to sort an array of points such that most of the array neighbors are also spatially close to each other. Works only if double is IEEE 754 standard.- Parameters:
x1
- The x coordinate of first pointy1
- The y coordinate of first pointx2
- The x coordinate of second pointy2
- The y coordinate of second point- Returns:
- Returns -1, 0, or 1, depending if first point is less than, equal to, or greater than the second one in the Morton order (lookup the Z-order curve on Wikipedia).
-
compareZOrder
public static int compareZOrder(Point2D pt1, Point2D pt2)
Compares two points spatially using z-order. The method can be used to sort an array of points such that most of the array neighbors are also spatially close to each other. Works only if double is IEEE 754 standard.- Parameters:
pt1
- The first pointpt2
- The second point- Returns:
- Returns -1, 0, or 1, depending if first point is less than, equal to, or greater than the second one in the Morton order (lookup the Z-order curve on Wikipedia).
-
getClosestCoordinate
public static double getClosestCoordinate(Point2D start_point, Point2D end_point, Point2D point_of_interest, boolean extrapolate)
Finds closest coordinate to a straight line defined by two endpoints and returns the interpolation factor. The closest point can be found then passing the returned value to Point_2D::lerp. Equivalent to Line::get_closest_coordinate.- Parameters:
start_point
- the start point of the line segment.end_point
- the end point of the line segment.point_of_interest
- the point to find the closest point to.extrapolate
- When false, only points inside of the line segment are returned. When true, any point on an infinite line passing through thesegment can be returned.- Returns:
- Returns the interpolation factor (t-parameter) that can be used to get the actual point on the line (use lerp() method for that).
-
-