List of usage examples for com.google.common.geometry S2Point add
public static S2Point add(final S2Point p1, final S2Point p2)
From source file:org.geosde.cassandra.GeometryTestCase.java
S2Point samplePoint(S2Cap cap) {
// We consider the cap axis to be the "z" axis. We choose two other axes
// to//w w w . j a v a2s .co m
// complete the coordinate frame.
S2Point z = cap.axis();
S2Point x = z.ortho();
S2Point y = S2Point.crossProd(z, x);
// The surface area of a spherical cap is directly proportional to its
// height. First we choose a random height, and then we choose a random
// point along the circle at that height.
double h = rand.nextDouble() * cap.height();
double theta = 2 * S2.M_PI * rand.nextDouble();
double r = Math.sqrt(h * (2 - h)); // Radius of circle.
// (cos(theta)*r*x + sin(theta)*r*y + (1-h)*z).Normalize()
return S2Point.normalize(
S2Point.add(S2Point.add(S2Point.mul(x, Math.cos(theta) * r), S2Point.mul(y, Math.sin(theta) * r)),
S2Point.mul(z, (1 - h))));
}