public static ProjectOntoLine ( Vector3D p, Vector3D lineP1, Vector3D lineP2 ) : Vector3D | ||
p | Vector3D | |
lineP1 | Vector3D | |
lineP2 | Vector3D | |
Résultat | Vector3D |
/// <summary> /// Normalize so P1 is closest point to origin, /// and direction vector is of unit length. /// </summary> public void NormalizeLine() { if (!this.IsLine) { return; } Vector3D d = P2 - P1; d.Normalize(); P1 = Euclidean2D.ProjectOntoLine(new Vector3D(), P1, P2); // ZZZ - Could probably do something more robust to choose proper direction. if (Tolerance.GreaterThanOrEqual(Euclidean2D.AngleToClock(d, new Vector3D(1, 0)), Math.PI)) { d *= -1; } P2 = P1 + d; }
/// <summary> /// Reflects a point in a line defined by two points. /// </summary> public static Vector3D ReflectPointInLine(Vector3D input, Vector3D p1, Vector3D p2) { Vector3D p = Euclidean2D.ProjectOntoLine(input, p1, p2); return(input + (p - input) * 2); }