/** * Get the direction one must travel from A to get to B. * * @param thetaA * The azimuth of point A * @param phiA * The polar angle of point A * @param thetaB * The azimuth of point B * @param phiB * The polar angle of point B * @return The angle from A to B, in radians, counterclockwise from due East */ public static double getAzimuth (double thetaA, double phiA, double thetaB, double phiB) { if (equal(0.0, phiA)) return -Math.PI / 2.0; if (equal(Math.PI, phiA)) return Math.PI / 2.0; Vector A = toUnitVector(thetaA, phiA); Vector B = toUnitVector(thetaB, phiB); Vector AB = A.cross(B).cross(A); Vector AN = A.cross(Z).cross(A); Vector AE = AN.cross(A); double deltaX = AB.dot(AE); double deltaY = AB.dot(AN); return Math.atan2(deltaY, deltaX); }
/** * Get the direction one must travel from A to get to B. * * @param thetaA * The azimuth of point A * @param phiA * The polar angle of point A * @param thetaB * The azimuth of point B * @param phiB * The polar angle of point B * @return The angle from A to B, in radians, counterclockwise from due East */ public static double getAzimuth (double thetaA, double phiA, double thetaB, double phiB) { if (equal(0.0, phiA)) return -Math.PI / 2.0; if (equal(Math.PI, phiA)) return Math.PI / 2.0; Vector A = toUnitVector(thetaA, phiA); Vector B = toUnitVector(thetaB, phiB); Vector AB = A.cross(B).cross(A); Vector AN = A.cross(Z).cross(A); Vector AE = AN.cross(A); double deltaX = AB.dot(AE); double deltaY = AB.dot(AN); return Math.atan2(deltaY, deltaX); }
@Test public void testCrossProduct () { Vector X = new Vector(1, 0, 0); Vector Y = new Vector(0, 1, 0); Vector Z = new Vector(0, 0, 1); Assert.assertEquals(Z, X.cross(Y)); Assert.assertEquals(Y, Z.cross(X)); Assert.assertEquals(X, Y.cross(Z)); Assert.assertEquals(Z.scale(-1.0), Y.cross(X)); Assert.assertEquals(Y.scale(-1.0), X.cross(Z)); Assert.assertEquals(X.scale(-1.0), Z.cross(Y)); } }