// Functions assumes ellipsoid scaled coordinates public static Double ComputeMagnitude(Vector3 point, Vector3 sphereCenter) { var magnitudeSquared = Cartesian3D.MagnitudeSquared(point); var magnitude = Math.Sqrt(magnitudeSquared); var direction = Cartesian3D.MultiplyByScalar(point, 1 / magnitude); magnitudeSquared = Math.Max(1.0, magnitudeSquared); magnitude = Math.Max(1.0, magnitude); var cosAlpha = DotProduct(direction, sphereCenter); var sinAlpha = Cartesian3D.Magnitude(CrossProduct(direction, sphereCenter)); var cosBeta = 1.0 / magnitude; var sinBeta = Math.Sqrt(magnitudeSquared - 1.0) * cosBeta; return(1.0 / (cosAlpha * cosBeta - sinAlpha * sinBeta)); }
public static Vector3 CrossProduct(Vector3 A, Vector3 B) { return(new Vector3(A.Y * B.Z - B.Y * A.Z, A.Z * B.X - B.Z * A.X, A.X * B.Y - B.X * A.Y)); }
/* * wgs84_a = radiusX # Semi-major axis * wgs84_b = radiusZ # Semi-minor axis * wgs84_e2 = 0.0066943799901975848 # First eccentricity squared * wgs84_a2 = wgs84_a** 2 # To speed things up a bit * wgs84_b2 = wgs84_b** 2 */ public static Double DotProduct(Vector3 pt1, Vector3 pt2) { return(pt1.X * pt2.X + pt1.Y * pt2.Y + pt1.Z * pt2.Z); }