/// <summary> /// Rotates the specified vector counter-clockwise around its origin /// by the specified angle in radians. /// </summary> /// <remarks> /// See http://stackoverflow.com/questions/4780119/2d-euclidean-vector-rotations for details. /// </remarks> /// <param name="v">Vector to rotate.</param> /// <param name="theta">Angle to rotate by, in radians.</param> /// <returns>Rotated vector.</returns> public static Vector2F Rotate(Vector2F v, float theta) { var cos = Angle.Cos(theta); var sin = Angle.Sin(theta); var newX = v.X * cos - v.Y * sin; var newY = v.X * sin + v.Y * cos; return(new Vector2F(newX, newY)); }
/// <summary> /// Height of a projectile with initial velocity <paramref name="v" /> launched at angle /// <paramref name="theta" /> in radians after it has traveled distance <paramref name="x" />. /// </summary> /// <param name="x">Position to get the projectile height at.</param> /// <param name="theta">Projectile launch angle.</param> /// <param name="v">Initial projectile velocity.</param> /// <returns>Projectile height after the specified distance.</returns> public static float Height(float x, float theta, float v) { return(x * Angle.Tan(theta) - ((G * (x * x)) / (2 * MathF.Pow(v * Angle.Cos(theta), 2)))); }
/// <summary> /// Orthogonally projects <paramref name="v" /> onto a straight line /// parallel to <paramref name="w" />. /// </summary> /// <remarks> /// See https://en.wikipedia.org/wiki/Vector_projection for details. /// </remarks> /// <param name="v">Vector to project.</param> /// <param name="w">Vector to project onto.</param> /// <returns>Projected vector.</returns> public static Vector2F Project(Vector2F v, Vector2F w) { return(v.Length * Angle.Cos(Angle.Between(v, w)) * w.Normalize()); }