/// <summary> /// Gets the normal for the given time. /// </summary> /// <param name="time">The time</param> /// <returns>The normal.</returns> public Vector2 GetPositionNormal(float time) { float offsetTime = time + 0.0001f; Vector2 a = GetPosition(time); Vector2 b = GetPosition(offsetTime); Vector2 output, temp; Vector2.Subtract(ref a, ref b, out temp); #if (XBOX360 || WINDOWS_PHONE) output = new Vector2(); #endif output.X = -temp.Y; output.Y = temp.X; Vector2.Normalize(ref output, out output); return(output); }
public static float DistanceBetweenPointAndLineSegment(ref Vector2 point, ref Vector2 lineEndPoint1, ref Vector2 lineEndPoint2) { Vector2 v = Vector2.Subtract(lineEndPoint2, lineEndPoint1); Vector2 w = Vector2.Subtract(point, lineEndPoint1); float c1 = Vector2.Dot(w, v); if (c1 <= 0) { return(DistanceBetweenPointAndPoint(ref point, ref lineEndPoint1)); } float c2 = Vector2.Dot(v, v); if (c2 <= c1) { return(DistanceBetweenPointAndPoint(ref point, ref lineEndPoint2)); } float b = c1 / c2; Vector2 pointOnLine = Vector2.Add(lineEndPoint1, Vector2.Multiply(v, b)); return(DistanceBetweenPointAndPoint(ref point, ref pointOnLine)); }
public static float DistanceBetweenPointAndPoint(ref Vector2 point1, ref Vector2 point2) { Vector2 v; Vector2.Subtract(ref point1, ref point2, out v); return v.Length; }