Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is there any quick way to find the intersection point between Plane and Ray?

share|improve this question
    
Try googling "line plane intersection" –  brandon Feb 1 '12 at 14:27
1  
An intersection between a Vector3 and a Plane doesn't make sense. You can find the intersection between a Plane and a line segment, a ray, or a line, but all of these require not one, but two Vector3's to be represented. Or you can check if a certain Point lies on the Plane or not. Which of these are you trying to achieve? –  David Gouveia Feb 1 '12 at 14:30
    
i am using the Vector3 as a Direction , Mmm it should be a Ray not a Vector3 –  MhdSyrwan Feb 1 '12 at 14:38
2  
    
long story short, study linear algebra –  brandon Feb 1 '12 at 14:51
show 1 more comment

1 Answer 1

up vote 5 down vote accepted

Try the following method which relies on XNA's built in Math API to intersect a Ray and a Plane and get back the point of intersection:

Vector3? GetRayPlaneIntersectionPoint(Ray ray, Plane plane)
{
    float? distance = ray.Intersects(plane);
    return distance.HasValue ? ray.Position + ray.Direction * distance.Value : null;
}

The method returns null if there's no intersection, or the point of intersection otherwise.

share|improve this answer
    
thanks very much :) , i thought it returns just a boolean –  MhdSyrwan Feb 1 '12 at 15:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.