// (1): xf = xi + vi cos(th) t + 1/2 ax t^2 // xf - xi = vi cos(th) t // t t = (xf - xi) / (vi cos(th)) (1.1) // (2): yf = yi + vi sin(th) t + 1/2 ay t^2 // yf - yi = vi sin(th) t + 1/2 ay t^2 // /. (1.1) yf - yi = vi sin(th) {(xf - xi) / (vi cos(th))} + 1/2 ay {(xf - xi) / (vi cos(th))}^2 // yf - yi = sin(th) (xf - xi) / cos(th) + 1/2 ay (xf - xi)^2 / (vi^2 cos^2(th)) // * 2 cos^2(th) 2 cos^2(th) (yf - yi) = 2 cos^2(th) sin(th) (xf - xi) / cos(th) + 2 cos^2(th) 1/2 ay (xf - xi)^2 / (vi^2 cos^2(th)) // 2 cos^2(th) (yf - yi) = 2 cos(th) sin(th) (xf - xi) + ay (xf - xi)^2 / vi^2 // power-reducing / half angle identity cos^2(x) = [1 + cos(2x)]/2 : // 2 [1 + cos(2 th)]/2 yf = 2 cos(th) sin(th) xf + ay xf^2 / vi^2 // [1 + cos(2 th)] yf = 2 cos(th) sin(th) xf + ay xf^2 / vi^2 // double angle formula 2 sin(x) cos(x) = sin(2x) : // [1 + cos(2 th)] yf = sin(2 th) xf + ay xf^2 / vi^2 // yf + yf cos(2 th) = sin(2 th) xf + ay xf^2 / vi^2 // sin(2 th) xf - yf cos(2 th) = yf - ay xf^2 / vi^2 // xf = r cos(phi) // yf = r sin(phi) // sin(2 th) r cos(phi) - r sin(phi) cos(2 th) = yf - ay xf^2 / vi^2 // r [ sin(2 th) cos(phi) - sin(phi) cos(2 th) ] = yf - ay xf^2 / vi^2 // sum/difference identity sin(x) cos(y) - sin(y) cos(x) = sin(x - y) : // r sin(2 th - phi) = yf - ay xf^2 / vi^2 // r = sqrt(xf^2 + yf^2) // sqrt(xf^2 + yf^2) sin(2 th - phi) = yf - ay xf^2 / vi^2 // tan(phi) = yf / xf phi = arctan(yf / xf): // sqrt(xf^2 + yf^2) sin(2 th - arctan(yf / xf)) = yf - ay xf^2 / vi^2 // sin(2 th - arctan(yf / xf)) = [yf - ay xf^2 / vi^2] / sqrt(xf^2 + yf^2) // // arcsin 1: 2 th - arctan(yf / xf) = arcsin{[yf - ay xf^2 / vi^2] / sqrt(xf^2 + yf^2)} (arcsin1) // // and // // arcsin 2: 2 th - arctan(yf / xf) = PI - arcsin{[yf - ay xf^2 / vi^2] / sqrt(xf^2 + yf^2)} (arcsin2) // (arcsin1): // // 2 th - arctan(yf / xf) = arcsin{[yf - ay xf^2 / vi^2] / sqrt(xf^2 + yf^2)} // 2 th = arcsin{[yf - ay xf^2 / vi^2] / sqrt(xf^2 + yf^2)} + arctan(yf / xf) // th = {arcsin{[yf - ay xf^2 / vi^2] / sqrt(xf^2 + yf^2)} + arctan(yf / xf)} / 2 // (arcsin2): // // 2 th - arctan(yf / xf) = PI - arcsin{[yf - ay xf^2 / vi^2] / sqrt(xf^2 + yf^2)} // 2 th = PI - arcsin{[yf - ay xf^2 / vi^2] / sqrt(xf^2 + yf^2)} + arctan(yf / xf) // th = [PI - arcsin{[yf - ay xf^2 / vi^2] / sqrt(xf^2 + yf^2)} + arctan(yf / xf)] / 2 #endregion public static MathObject InitialAngle(Obj a, Obj b, int solution = 0, int n = 0) { if (Misc.NotNull( a.position.x, b.position.x, a.position.y, b.position.y, a.speed, a.acceleration.y) && a.speed != 0 && a.speed != 0.0) { var xf = b.position.x - a.position.x; var yf = b.position.y - a.position.y; var vi = a.speed; var ay = a.acceleration.y; if (solution == 0) { return ((Trig.Asin((yf - ay * (xf ^ 2) / (vi ^ 2)) / Misc.Sqrt((xf ^ 2) + (yf ^ 2))) + Trig.Atan2(yf, xf)) / 2); } else if (solution == 1) { return ((Trig.Pi - Trig.Asin((yf - ay * (xf ^ 2) / (vi ^ 2)) / Misc.Sqrt((xf ^ 2) + (yf ^ 2))) + Trig.Atan2(yf, xf)) / 2); } } throw new Exception(); }
public MathObject ToAngle() { return(Trig.Atan2(y, x)); }