lib/azimuth.js
function rotateGlobe(b, a, bRadius) {
  var br, brp, alat, acos, asin, bx, by, bz;

  // Get modified coordinates of 'b' by rotating the globe so
  // that 'a' is at lat=0, lng=0
  br = { lat: b.lat, lng: (b.lng - a.lng), elv:b.elv };
  brp = locationToPoint(br);

  // scale all the coordinates based on the original, correct geoid radius
  brp.x *= (bRadius / brp.radius);
  brp.y *= (bRadius / brp.radius);
  brp.z *= (bRadius / brp.radius);

  // restore actual geoid-based radius calculation
  brp.radius = bRadius;

  // Rotate brp cartesian coordinates around the z-axis by a.lng degrees,
  // then around the y-axis by a.lat degrees.
  // Though we are decreasing by a.lat degrees, as seen above the y-axis,
  // this is a positive (counterclockwise) rotation
  // (if B's longitude is east of A's).
  // However, from this point of view the x-axis is pointing left.
  // So we will look the other way making the x-axis pointing right, the z-axis
  // pointing up, and the rotation treated as negative.
  alat = -a.lat * Math.PI / 180.0;
  acos = Math.cos(alat);
  asin = Math.sin(alat);

  bx = (brp.x * acos) - (brp.z * asin);
  by = brp.y;
  bz = (brp.x * asin) + (brp.z * acos);

  return { x: bx, y: by, z: bz };
}
function rotateGlobe(b, a, bRadius) {
  var br, brp, alat, acos, asin, bx, by, bz;

  // Get modified coordinates of 'b' by rotating the globe so
  // that 'a' is at lat=0, lng=0
  br = { lat: b.lat, lng: (b.lng - a.lng), elv:b.elv };
  brp = locationToPoint(br);

  // scale all the coordinates based on the original, correct geoid radius
  brp.x *= (bRadius / brp.radius);
  brp.y *= (bRadius / brp.radius);
  brp.z *= (bRadius / brp.radius);

  // restore actual geoid-based radius calculation
  brp.radius = bRadius;

  // Rotate brp cartesian coordinates around the z-axis by a.lng degrees,
  // then around the y-axis by a.lat degrees.
  // Though we are decreasing by a.lat degrees, as seen above the y-axis,
  // this is a positive (counterclockwise) rotation
  // (if B's longitude is east of A's).
  // However, from this point of view the x-axis is pointing left.
  // So we will look the other way making the x-axis pointing right, the z-axis
  // pointing up, and the rotation treated as negative.
  alat = -a.lat * Math.PI / 180.0;
  acos = Math.cos(alat);
  asin = Math.sin(alat);

  bx = (brp.x * acos) - (brp.z * asin);
  by = brp.y;
  bz = (brp.x * asin) + (brp.z * acos);

  return { x: bx, y: by, z: bz };
}
function rotateGlobe ( b , a , bRadius ) { var br , brp , alat , acos , asin , bx , by , bz ; // Get modified coordinates of 'b' by rotating the globe so // that 'a' is at lat=0, lng=0 br = { lat : b . lat , lng : ( b . lng - a . lng ) , elv : b . elv } ; brp = locationToPoint ( br ) ; // scale all the coordinates based on the original, correct geoid radius brp . x *= ( bRadius / brp . radius ) ; brp . y *= ( bRadius / brp . radius ) ; brp . z *= ( bRadius / brp . radius ) ; // restore actual geoid-based radius calculation brp . radius = bRadius ; // Rotate brp cartesian coordinates around the z-axis by a.lng degrees, // then around the y-axis by a.lat degrees. // Though we are decreasing by a.lat degrees, as seen above the y-axis, // this is a positive (counterclockwise) rotation // (if B's longitude is east of A's). // However, from this point of view the x-axis is pointing left. // So we will look the other way making the x-axis pointing right, the z-axis // pointing up, and the rotation treated as negative. alat = - a . lat * Math . PI / 180.0 ; acos = Math . cos ( alat ) ; asin = Math . sin ( alat ) ; bx = ( brp . x * acos ) - ( brp . z * asin ) ; by = brp . y ; bz = ( brp . x * asin ) + ( brp . z * acos ) ; return { x : bx , y : by , z : bz } ; }
Gets rotated point

@param {Object} b
@param {Object} a
@param {Number} bRadius
@returns {Object}
Gets rotated point