public static ProjectOntoLine ( Vector3D nl, Vector3D pl, Vector3D point ) : Vector3D | ||
nl | Vector3D | |
pl | Vector3D | |
point | Vector3D | |
return | Vector3D |
public static Vector3D ProjectOntoLine( Vector3D nl, Vector3D pl, Vector3D point )
{
// http://gamedev.stackexchange.com/a/72529
// A + dot(AP,AB) / dot(AB,AB) * AB
Vector3D AP = point - pl;
Vector3D AB = nl;
return pl + AB * AP.Dot( AB ) / AB.Dot( AB );
}
public static void TranslateSphere(Sphere s, Vector3D t) { if (s.IsPlane) { Vector3D offsetAlongNormal = Euclidean3D.ProjectOntoLine(s.Normal, new Vector3D(), t); s.Offset += offsetAlongNormal; } else { s.Center += t; } }