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

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

Introduction

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

Prototype

public static S2Point crossProd(final S2Point p1, final S2Point p2) 

Source Link

Usage

From source file:org.geosde.cassandra.GeometryTestCase.java

/**
 * Return a right-handed coordinate frame (three orthonormal vectors).
 * Returns an array of three points: x,y,z
 *//*from   w ww  .  j  a v a2 s. co  m*/
public ImmutableList<S2Point> getRandomFrame() {
    S2Point p0 = randomPoint();
    S2Point p1 = S2Point.normalize(S2Point.crossProd(p0, randomPoint()));
    S2Point p2 = S2Point.normalize(S2Point.crossProd(p0, p1));
    return ImmutableList.of(p0, p1, 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/*from   w  ww . j  a v  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))));
}