Example usage for com.google.common.geometry S2Cap height

List of usage examples for com.google.common.geometry S2Cap height

Introduction

In this page you can find the example usage for com.google.common.geometry S2Cap height.

Prototype

double height

To view the source code for com.google.common.geometry S2Cap height.

Click 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.ja  v a 2s.  c om*/
    // 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))));
}