/// <summary> /// Given different v1 and v2, which are both unit vectors on /// sphere, we can get a great circle path from v1 to v2 (choose the /// shortest great circle path). We walk the path by angle alpha from /// v1 towards v2. This returns the point we end up with, which is /// an unit vector. /// If v1 == v2, an exception is thrown. /// If v1 == -v2, the chosen path is the one that goes through /// the north pole, if none of v1, v2 is north pole. Otherwise, /// the point with lat:0, lon:0. /// </summary> public static Vector3D GetV(Vector3D v1, Vector3D v2, double alpha) { double t = v1.Dot(v2); if (t >= 1.0) { throw new ArgumentException(); } if (t <= -1.0) { if (v1.Equals(NorthPole) || v2.Equals(NorthPole)) { return(GetV(v1, Lat0Lon0, alpha)); } return(GetV(v1, NorthPole, alpha)); } var matrix = new Matrix2by2(1.0, t, t, 1.0); double beta = Acos(t); var b = new Vector2D(Cos(alpha), Cos(beta - alpha)); var a = matrix.Inverse().Multiply(b); return(v1 * a.X + v2 * a.Y); }
public Matrix2by2 Inverse() { var det = Determinant; if (det == 0.0) { throw new InvalidOperationException(); } var B = new Matrix2by2(A22, -A12, -A21, A11); B.Multiply(1.0 / det); return(B); }