Example usage for com.google.common.geometry S2Point mul

List of usage examples for com.google.common.geometry S2Point mul

Introduction

In this page you can find the example usage for com.google.common.geometry S2Point mul.

Prototype

public static S2Point mul(final S2Point p, double m) 

Source Link

Usage

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 ww . jav a  2 s.  c o  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))));
}