Class S2Point

  • All Implemented Interfaces:
    S2Region, java.io.Serializable, java.lang.Comparable<S2Point>
    Direct Known Subclasses:
    S2Shape.ReferencePoint

    @GwtCompatible(serializable=true)
    @CheckReturnValue
    public class S2Point
    extends java.lang.Object
    implements S2Region, java.lang.Comparable<S2Point>, java.io.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
    • 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.
      • x

        final double x
      • y

        final double y
      • z

        final double z
    • Constructor Detail

      • S2Point

        public S2Point()
      • S2Point

        public S2Point​(double x,
                       double y,
                       double z)
    • 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 S2Point crossProd​(S2Point p)
        Returns crossProd(this,p).
      • 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 magnitude sqrt(x*x+y*y+z*z).
      • norm2

        public final double norm2()
        Returns the square of the vector magnitude x*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.

      • 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 using S1ChordAngle.

      • 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
      • 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

        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
      • aequal

        boolean aequal​(S2Point that,
                       double margin)
        Compare two vectors, return true if all their components are within a difference of margin.
      • equals

        public boolean equals​(java.lang.Object that)
        Overrides:
        equals in class java.lang.Object
      • equalsPoint

        public boolean equalsPoint​(S2Point that)
        Returns true if this point is equal to that. Slightly faster than equals(Object).
      • lessThan

        public boolean lessThan​(S2Point vb)
      • compareTo

        public int compareTo​(S2Point other)
        Specified by:
        compareTo in interface java.lang.Comparable<S2Point>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toDegreesString

        public java.lang.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.
        Overrides:
        hashCode in class java.lang.Object
      • contains

        public boolean contains​(S2Cell cell)
        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.
        Specified by:
        contains in interface S2Region
      • contains

        public boolean contains​(S2Point other)
        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.
        Specified by:
        contains in interface S2Region
      • getCapBound

        public S2Cap getCapBound()
        Description copied from interface: S2Region
        Return a bounding spherical cap.
        Specified by:
        getCapBound in interface S2Region
      • mayIntersect

        public boolean mayIntersect​(S2Cell cell)
        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 interface S2Region
      • encode

        public void encode​(java.io.OutputStream os)
                    throws java.io.IOException
        Writes this point to the given output stream.
        Throws:
        java.io.IOException
      • encode

        void encode​(LittleEndianOutput os)
             throws java.io.IOException
        Writes this point to the given little endian output stream.
        Throws:
        java.io.IOException
      • decode

        public static S2Point decode​(java.io.InputStream is)
                              throws java.io.IOException
        Returns a new S2Point decoded from the given input stream.
        Throws:
        java.io.IOException
      • decode

        static S2Point decode​(LittleEndianInput is)
                       throws java.io.IOException
        Returns a new S2Point decoded from the given little endian input stream.
        Throws:
        java.io.IOException