Note that there are some explanatory texts on larger screens.

plurals
  1. PO3D Line Segment and Plane Intersection
    primarykey
    data
    text
    <p>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 the contact point on the plane where the line intersects, if the line does not intersect, the function should still return the intersection point had the line segmenent had been a ray. I used the information and code from Christer Ericson's Real-time Collision Detection but I don't think im implementing it correctly. </p> <p>The plane im using is derived from the normal and vertice of a triangle. Finding the location of intersection on the plane is what i want, regardless of whether or not it is located on the triangle i used to derive the plane.</p> <p><img src="https://i.stack.imgur.com/W91Ld.png" alt="enter image description here"></p> <p>The parameters of the function are as follows:</p> <pre><code>contact = the contact point on the plane, this is what i want calculated ray = B - A, simply the line from A to B rayOrigin = A, the origin of the line segement normal = normal of the plane (normal of a triangle) coord = a point on the plane (vertice of a triangle) </code></pre> <p>Here's the code im using:</p> <pre><code>bool linePlaneIntersection(Vector&amp; contact, Vector ray, Vector rayOrigin, Vector normal, Vector coord) { // calculate plane float d = Dot(normal, coord); if (Dot(normal, ray)) { return false; // avoid divide by zero } // Compute the t value for the directed line ray intersecting the plane float t = (d - Dot(normal, rayOrigin)) / Dot(normal, ray); // scale the ray by t Vector newRay = ray * t; // calc contact point contact = rayOrigin + newRay; if (t &gt;= 0.0f &amp;&amp; t &lt;= 1.0f) { return true; // line intersects plane } return false; // line does not } </code></pre> <p>In my tests, it never returns true... any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload