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 classA builder ofS2Pointinstances.static classAn S2Shape representing a list of S2Points. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final S2PointOrigin of the coordinate system, [0,0,0].(package private) final doublestatic final S2PointOpposite direction of the x-axis.static final S2PointDirection of the x-axis.(package private) final doublestatic final S2PointOpposite direction of the y-axis.static final S2PointDirection of the y-axis.(package private) final doublestatic final S2PointOpposite direction of the z-axis.static final S2PointDirection of the z-axis. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns add(this,p).static final S2PointReturns the component-wise addition of 'p1' and 'p2'.(package private) booleanCompare two vectors, return true if all their components are within a difference of margin.final doubleReturn the angle between two vectors in radiansintbooleanIf this method returns true, the region completely contains the given cell.booleanReturns true if and only if the given point is contained by the region.Returns crossProd(this,p).static final S2PointReturns the R3 vector cross product of 'p1' and 'p2'.final doublecrossProdNorm(S2Point va) Returns the norm of the cross product,S2Point.crossProd(this, va).norm().(package private) static S2PointReturns a new S2Point decoded from the given little endian input stream.static S2Pointdecode(InputStream is) Returns a new S2Point decoded from the given input stream.div(double scale) Returns div(this,scale).static final S2PointReturns the component-wise division of 'p' by 'm'.final doubleReturns the vector dot product of 'this' with 'that'.(package private) voidWrites this point to the given little endian output stream.voidencode(OutputStream os) Writes this point to the given output stream.booleanbooleanequalsPoint(S2Point that) Returns true if this point is equal tothat.fabs()Returns fabs(this).static final S2PointReturns the component-wise absolute point from 'p'.final doubleget(int axis) Return a bounding spherical cap.doublegetDistance(S2Point that) Returns the distance in 3D coordinates from this to that.doublegetDistance2(S2Point that) Returns the square of the distance in 3D coordinates from this to that.Return a bounding latitude-longitude rectangle.doublegetX()doublegetY()doublegetZ()inthashCode()Calcualates hashcode based on stored coordinates.final intReturn the index of the largest component fabs(package private) static final intlargestAbsComponent(double x, double y, double z) Return the index of the largest component fabsbooleanbooleanmayIntersect(S2Cell cell) If this method returns false, the region does not intersect the given cell.static final S2PointReturns sub(this,p).mul(double scale) Returns mul(this,scale).static final S2PointReturns the component-wise multiplication of 'p' with 'm'.neg()Returns neg(this).static final S2PointReturns the component-wise negation of 'p', i.e.doublenorm()Returns the vector magnitudesqrt(x*x+y*y+z*z).final doublenorm2()Returns the square of the vector magnitudex*x+y*y+z*z.Returns normalize(this).static final S2PointReturns a copy of 'p' rescaled to be unit-length.final S2Pointortho()return a vector orthogonal to this oneRotates this point around an arbitrary axis.static final doublescalarTripleProduct(S2Point a, S2Point b, S2Point c) Returns the scalar triple product,a.dotProd(b.crossProd(c)).Returns sub(this,p).static final S2PointReturns 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:
compareToin 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:S2RegionIf 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:S2RegionReturns true if and only if the given point is contained by the region.pis generally required to be unit length, although some subtypes may relax this restriction. -
getCapBound
Description copied from interface:S2RegionReturn a bounding spherical cap.- Specified by:
getCapBoundin interfaceS2Region
-
getRectBound
Description copied from interface:S2RegionReturn a bounding latitude-longitude rectangle.- Specified by:
getRectBoundin interfaceS2Region
-
mayIntersect
Description copied from interface:S2RegionIf 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:
mayIntersectin 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
-