3D Line Segment and Plane Intersection

后端 未结 3 864
孤街浪徒
孤街浪徒 2020-12-29 16:09

I\'m trying to implement a line segment and plane intersection test that will return true or false depending on whether or not it intersects the plane. It also will return t

3条回答
  •  粉色の甜心
    2020-12-29 16:55

    I could be wrong about this, but there are a few spots in the code that seem very suspicious. To begin, consider this line:

    // calculate plane
    float d = Dot(normal, coord);
    

    Here, your value d corresponds to the dot product between the plane normal (a vector) and a point in space (a point on the plane). This seems wrong. In particular, if you have any plane passing through the origin and use the origin as the coordinate point, you will end up computing

    d = Dot(normal, (0, 0, 0)) = 0
    

    And immediately returning false. I'm not sure what you intended to do here, but I'm pretty sure that this isn't what you meant.

    Another spot in the code that seems suspicious is this line:

    // Compute the t value for the directed line ray intersecting the plane
    float t = (d - Dot(normal, rayOrigin)) / Dot(normal, ray);
    

    Note that you're computing the dot product between the plane's normal vector (a vector) and the ray's origin point (a point in space). This seems weird because it means that depending on where the ray originates in space, the scaling factor you use for the ray changes. I would suggest looking at this code one more time to see if this is really what you meant.

    Hope this helps!

提交回复
热议问题