Package com.google.common.geometry
Class S2Point
java.lang.Object
com.google.common.geometry.S2Point
- All Implemented Interfaces:
S2Region
,Serializable
,Comparable<S2Point>
- Direct Known Subclasses:
S2Shape.ReferencePoint
@GwtCompatible(serializable=true)
@CheckReturnValue
public class S2Point
extends Object
implements S2Region, Comparable<S2Point>, Serializable
An S2Point represents a point on the unit sphere as a 3D vector. Usually points are normalized to
be unit length, but some methods do not require this.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
A builder ofS2Point
instances.static class
An S2Shape representing a list of S2Points. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final S2Point
Origin of the coordinate system, [0,0,0].(package private) final double
static final S2Point
Opposite direction of the x-axis.static final S2Point
Direction of the x-axis.(package private) final double
static final S2Point
Opposite direction of the y-axis.static final S2Point
Direction of the y-axis.(package private) final double
static final S2Point
Opposite direction of the z-axis.static final S2Point
Direction of the z-axis. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns add(this,p).static final S2Point
Returns the component-wise addition of 'p1' and 'p2'.(package private) boolean
Compare two vectors, return true if all their components are within a difference of margin.final double
Return the angle between two vectors in radiansint
boolean
If this method returns true, the region completely contains the given cell.boolean
Returns true if and only if the given point is contained by the region.Returns crossProd(this,p).static final S2Point
Returns the R3 vector cross product of 'p1' and 'p2'.final double
crossProdNorm
(S2Point va) Returns the norm of the cross product,S2Point.crossProd(this, va).norm()
.(package private) static S2Point
Returns a new S2Point decoded from the given little endian input stream.static S2Point
decode
(InputStream is) Returns a new S2Point decoded from the given input stream.div
(double scale) Returns div(this,scale).static final S2Point
Returns the component-wise division of 'p' by 'm'.final double
Returns the vector dot product of 'this' with 'that'.(package private) void
Writes this point to the given little endian output stream.void
encode
(OutputStream os) Writes this point to the given output stream.boolean
boolean
equalsPoint
(S2Point that) Returns true if this point is equal tothat
.fabs()
Returns fabs(this).static final S2Point
Returns the component-wise absolute point from 'p'.final double
get
(int axis) Return a bounding spherical cap.double
getDistance
(S2Point that) Returns the distance in 3D coordinates from this to that.double
getDistance2
(S2Point that) Returns the square of the distance in 3D coordinates from this to that.Return a bounding latitude-longitude rectangle.double
getX()
double
getY()
double
getZ()
int
hashCode()
Calcualates hashcode based on stored coordinates.final int
Return the index of the largest component fabs(package private) static final int
largestAbsComponent
(double x, double y, double z) Return the index of the largest component fabsboolean
boolean
mayIntersect
(S2Cell cell) If this method returns false, the region does not intersect the given cell.static final S2Point
Returns sub(this,p).mul
(double scale) Returns mul(this,scale).static final S2Point
Returns the component-wise multiplication of 'p' with 'm'.neg()
Returns neg(this).static final S2Point
Returns the component-wise negation of 'p', i.e.double
norm()
Returns the vector magnitudesqrt(x*x+y*y+z*z)
.final double
norm2()
Returns the square of the vector magnitudex*x+y*y+z*z
.Returns normalize(this).static final S2Point
Returns a copy of 'p' rescaled to be unit-length.final S2Point
ortho()
return a vector orthogonal to this oneRotates this point around an arbitrary axis.static final double
scalarTripleProduct
(S2Point a, S2Point b, S2Point c) Returns the scalar triple product,a.dotProd(b.crossProd(c))
.Returns sub(this,p).static final S2Point
Returns the component-wise subtraction of 'p1' and 'p2'.Returns a new Builder initialized to a copy of this point.toString()
-
Field Details
-
ORIGIN
Origin of the coordinate system, [0,0,0]. -
X_POS
Direction of the x-axis. -
X_NEG
Opposite direction of the x-axis. -
Y_POS
Direction of the y-axis. -
Y_NEG
Opposite direction of the y-axis. -
Z_POS
Direction of the z-axis. -
Z_NEG
Opposite direction of the z-axis. -
x
final double x -
y
final double y -
z
final double z
-
-
Constructor Details
-
S2Point
public S2Point() -
S2Point
public S2Point(double x, double y, double z)
-
-
Method Details
-
getX
public double getX() -
getY
public double getY() -
getZ
public double getZ() -
add
Returns add(this,p). -
add
Returns the component-wise addition of 'p1' and 'p2'. -
sub
Returns sub(this,p). -
sub
Returns the component-wise subtraction of 'p1' and 'p2'. -
minus
Returns sub(this,p). -
mul
Returns mul(this,scale). -
mul
Returns the component-wise multiplication of 'p' with 'm'. -
div
Returns div(this,scale). -
div
Returns the component-wise division of 'p' by 'm'. -
dotProd
Returns the vector dot product of 'this' with 'that'. -
crossProd
Returns crossProd(this,p). -
crossProd
Returns the R3 vector cross product of 'p1' and 'p2'. -
neg
Returns neg(this). -
neg
Returns the component-wise negation of 'p', i.e. its antipodal point. -
fabs
Returns fabs(this). -
fabs
Returns the component-wise absolute point from 'p'. -
normalize
Returns normalize(this). -
normalize
Returns a copy of 'p' rescaled to be unit-length. -
norm
public double norm()Returns the vector magnitudesqrt(x*x+y*y+z*z)
. -
norm2
public final double norm2()Returns the square of the vector magnitudex*x+y*y+z*z
. -
scalarTripleProduct
Returns the scalar triple product,a.dotProd(b.crossProd(c))
.This is a faster implementation than calling the dotProd and crossProd methods directly.
-
getDistance
Returns the distance in 3D coordinates from this to that.Equivalent to
a.sub(b).norm()
, but significantly faster.If ordering points by angle, this is faster than
norm()
, and much faster thanangle(com.google.common.geometry.S2Point)
, but consider usingS1ChordAngle
. -
getDistance2
Returns the square of the distance in 3D coordinates from this to that.Equivalent to
getDistance(that)<sup>2</sup>
, but significantly faster.If ordering points by angle, this is much faster than
angle(com.google.common.geometry.S2Point)
, but consider usingS1ChordAngle
. -
ortho
return a vector orthogonal to this one -
largestAbsComponent
public final int largestAbsComponent()Return the index of the largest component fabs -
largestAbsComponent
static final int largestAbsComponent(double x, double y, double z) Return the index of the largest component fabs -
get
public final double get(int axis) -
crossProdNorm
Returns the norm of the cross product,S2Point.crossProd(this, va).norm()
. This is more efficient than calling crossProd() followed by norm(). -
rotate
Rotates this point around an arbitrary axis. The result is normalized.- Parameters:
axis
- point around which rotation should be performed.radians
- radians to rotate the point counterclockwise around the given axis.
-
angle
Return the angle between two vectors in radians -
aequal
Compare two vectors, return true if all their components are within a difference of margin. -
equals
-
equalsPoint
Returns true if this point is equal tothat
. Slightly faster thanequals(Object)
. -
lessThan
-
compareTo
- Specified by:
compareTo
in interfaceComparable<S2Point>
-
toString
-
toDegreesString
-
toBuilder
Returns a new Builder initialized to a copy of this point. -
hashCode
public int hashCode()Calcualates hashcode based on stored coordinates. Since we want +0.0 and -0.0 to be treated the same, we ignore the sign of the coordinates. -
contains
Description copied from interface:S2Region
If this method returns true, the region completely contains the given cell. Otherwise, either the region does not contain the cell or the containment relationship could not be determined. -
contains
Description copied from interface:S2Region
Returns true if and only if the given point is contained by the region.p
is generally required to be unit length, although some subtypes may relax this restriction. -
getCapBound
Description copied from interface:S2Region
Return a bounding spherical cap.- Specified by:
getCapBound
in interfaceS2Region
-
getRectBound
Description copied from interface:S2Region
Return a bounding latitude-longitude rectangle.- Specified by:
getRectBound
in interfaceS2Region
-
mayIntersect
Description copied from interface:S2Region
If this method returns false, the region does not intersect the given cell. Otherwise, either region intersects the cell, or the intersection relationship could not be determined.- Specified by:
mayIntersect
in interfaceS2Region
-
encode
Writes this point to the given output stream.- Throws:
IOException
-
encode
Writes this point to the given little endian output stream.- Throws:
IOException
-
decode
Returns a new S2Point decoded from the given input stream.- Throws:
IOException
-
decode
Returns a new S2Point decoded from the given little endian input stream.- Throws:
IOException
-