Original Post
Hi, I'm using Plane.IntersectLine to find the point where a line intersects a plane in C# and Managed DirectX. I was wondering how I can retrieve the distance from the origin of my ray to the hit point on the plane. Heres an example: I think I'm being really slow with this, is it simply: Please confirm the answer, I having "one of those moments". Many Thanks, Chris
static void Main(string[] args)
{
// Ignore the values, they're just for show
Plane test = new Plane( 0.0f, 1.0f, 0.0f, 0.0f );
Vector3 origin = new Vector3( 5.0f, 10.0f, 5.0f );
Vector3 end = new Vector3( 10.0f, -10.0f, 0.0f );
Vector3 hitPoint = Plane.IntersectLine( test, origin, end );
}
float distance = Vector3.Length(hitPoint - origin);
// but I also remember this:
float distance = Vector3.Dot(hitPoint - origin, direction);
// Where "direction" is the direction the ray is travelling (end - origin).