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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classS2Point.BuilderA builder ofS2Pointinstances.static classS2Point.ShapeAn S2Shape representing a list of S2Points.
-
Field Summary
Fields Modifier and Type Field Description static S2PointORIGINOrigin of the coordinate system, [0,0,0].static S2PointX_NEGOpposite direction of the x-axis.static S2PointX_POSDirection of the x-axis.static S2PointY_NEGOpposite direction of the y-axis.static S2PointY_POSDirection of the y-axis.static S2PointZ_NEGOpposite direction of the z-axis.static S2PointZ_POSDirection of the z-axis.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description S2Pointadd(S2Point p)Returns add(this,p).static S2Pointadd(S2Point p1, S2Point p2)Returns the component-wise addition of 'p1' and 'p2'.doubleangle(S2Point va)Return the angle between two vectors in radiansintcompareTo(S2Point other)booleancontains(S2Cell cell)If this method returns true, the region completely contains the given cell.booleancontains(S2Point other)Returns true if and only if the given point is contained by the region.S2PointcrossProd(S2Point p)Returns crossProd(this,p).static S2PointcrossProd(S2Point p1, S2Point p2)Returns the R3 vector cross product of 'p1' and 'p2'.doublecrossProdNorm(S2Point va)Returns the norm of the cross product,S2Point.crossProd(this, va).norm().static S2Pointdecode(InputStream is)Returns a new S2Point decoded from the given input stream.S2Pointdiv(double scale)Returns div(this,scale).static S2Pointdiv(S2Point p, double m)Returns the component-wise division of 'p' by 'm'.doubledotProd(S2Point that)Returns the vector dot product of 'this' with 'that'.voidencode(OutputStream os)Writes this point to the given output stream.booleanequals(Object that)booleanequalsPoint(S2Point that)Returns true if this point is equal tothat.S2Pointfabs()Returns fabs(this).static S2Pointfabs(S2Point p)Returns the component-wise absolute point from 'p'.doubleget(int axis)S2CapgetCapBound()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.S2LatLngRectgetRectBound()Return a bounding latitude-longitude rectangle.doublegetX()doublegetY()doublegetZ()inthashCode()Calcualates hashcode based on stored coordinates.intlargestAbsComponent()Return the index of the largest component fabsbooleanlessThan(S2Point vb)booleanmayIntersect(S2Cell cell)If this method returns false, the region does not intersect the given cell.static S2Pointminus(S2Point p1, S2Point p2)Returns sub(this,p).S2Pointmul(double scale)Returns mul(this,scale).static S2Pointmul(S2Point p, double m)Returns the component-wise multiplication of 'p' with 'm'.S2Pointneg()Returns neg(this).static S2Pointneg(S2Point p)Returns the component-wise negation of 'p', i.e.doublenorm()Returns the vector magnitudesqrt(x*x+y*y+z*z).doublenorm2()Returns the square of the vector magnitudex*x+y*y+z*z.S2Pointnormalize()Returns normalize(this).static S2Pointnormalize(S2Point p)Returns a copy of 'p' rescaled to be unit-length.S2Pointortho()return a vector orthogonal to this oneS2Pointrotate(S2Point axis, double radians)Rotates this point around an arbitrary axis.static doublescalarTripleProduct(S2Point a, S2Point b, S2Point c)Returns the scalar triple product,a.dotProd(b.crossProd(c)).S2Pointsub(S2Point p)Returns sub(this,p).static S2Pointsub(S2Point p1, S2Point p2)Returns the component-wise subtraction of 'p1' and 'p2'.S2Point.BuildertoBuilder()Returns a new Builder initialized to a copy of this point.StringtoDegreesString()StringtoString()
-
-
-
Field Detail
-
ORIGIN
public static final S2Point ORIGIN
Origin of the coordinate system, [0,0,0].
-
X_POS
public static final S2Point X_POS
Direction of the x-axis.
-
X_NEG
public static final S2Point X_NEG
Opposite direction of the x-axis.
-
Y_POS
public static final S2Point Y_POS
Direction of the y-axis.
-
Y_NEG
public static final S2Point Y_NEG
Opposite direction of the y-axis.
-
Z_POS
public static final S2Point Z_POS
Direction of the z-axis.
-
Z_NEG
public static final S2Point Z_NEG
Opposite direction of the z-axis.
-
-
Method Detail
-
getX
public double getX()
-
getY
public double getY()
-
getZ
public double getZ()
-
add
public static final S2Point add(S2Point p1, S2Point p2)
Returns the component-wise addition of 'p1' and 'p2'.
-
sub
public static final S2Point sub(S2Point p1, S2Point p2)
Returns the component-wise subtraction of 'p1' and 'p2'.
-
mul
public S2Point mul(double scale)
Returns mul(this,scale).
-
mul
public static final S2Point mul(S2Point p, double m)
Returns the component-wise multiplication of 'p' with 'm'.
-
div
public S2Point div(double scale)
Returns div(this,scale).
-
div
public static final S2Point div(S2Point p, double m)
Returns the component-wise division of 'p' by 'm'.
-
dotProd
public final double dotProd(S2Point that)
Returns the vector dot product of 'this' with 'that'.
-
crossProd
public static final S2Point crossProd(S2Point p1, S2Point p2)
Returns the R3 vector cross product of 'p1' and 'p2'.
-
neg
public S2Point neg()
Returns neg(this).
-
neg
public static final S2Point neg(S2Point p)
Returns the component-wise negation of 'p', i.e. its antipodal point.
-
fabs
public S2Point fabs()
Returns fabs(this).
-
fabs
public static final S2Point fabs(S2Point p)
Returns the component-wise absolute point from 'p'.
-
normalize
public S2Point normalize()
Returns normalize(this).
-
normalize
public static final S2Point normalize(S2Point p)
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
public static final double scalarTripleProduct(S2Point a, S2Point b, S2Point c)
Returns the scalar triple product,a.dotProd(b.crossProd(c)).This is a faster implementation than calling the dotProd and crossProd methods directly.
-
getDistance
public double getDistance(S2Point that)
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
public double getDistance2(S2Point that)
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
public final S2Point ortho()
return a vector orthogonal to this one
-
largestAbsComponent
public final int largestAbsComponent()
Return the index of the largest component fabs
-
get
public final double get(int axis)
-
crossProdNorm
public final double crossProdNorm(S2Point va)
Returns the norm of the cross product,S2Point.crossProd(this, va).norm(). This is more efficient than calling crossProd() followed by norm().
-
rotate
public S2Point rotate(S2Point axis, double radians)
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
public final double angle(S2Point va)
Return the angle between two vectors in radians
-
equalsPoint
public boolean equalsPoint(S2Point that)
Returns true if this point is equal tothat. Slightly faster thanequals(Object).
-
lessThan
public boolean lessThan(S2Point vb)
-
compareTo
public int compareTo(S2Point other)
- Specified by:
compareToin interfaceComparable<S2Point>
-
toDegreesString
public String toDegreesString()
-
toBuilder
public S2Point.Builder 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
public boolean contains(S2Cell cell)
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
public boolean contains(S2Point other)
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
public S2Cap getCapBound()
Description copied from interface:S2RegionReturn a bounding spherical cap.- Specified by:
getCapBoundin interfaceS2Region
-
getRectBound
public S2LatLngRect getRectBound()
Description copied from interface:S2RegionReturn a bounding latitude-longitude rectangle.- Specified by:
getRectBoundin interfaceS2Region
-
mayIntersect
public boolean mayIntersect(S2Cell cell)
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
public void encode(OutputStream os) throws IOException
Writes this point to the given output stream.- Throws:
IOException
-
decode
public static S2Point decode(InputStream is) throws IOException
Returns a new S2Point decoded from the given input stream.- Throws:
IOException
-
-