Point in a Polygon

Started by
10 comments, last by oliii 19 years, 10 months ago
Quote:Original post by jyk
You can also form a plane for each edge of the poly whose normal points toward the interior of the poly. If the intersection point is in front of each of these planes, then it is in the poly. This method is also slow.


So 'n' dotproducts for an 'n' sided/surfaced polygon is slow?
Advertisement
for(int j = Poly.numverts-1, i = 0; i < Poly.numverts; j = i, i ++){    Vector E = Poly.V</span> - Poly.V<span class="cpp-number">[j]</span>;<br>    Vector D = P - V<span class="cpp-number"></span>;<br>    Vector En= E.Cross(Poly.Normal);<br>    <span class="cpp-keyword">float</span>  d = D.Dot(En);<br><br>    <span class="cpp-keyword">if</span> (d &lt; 0.0f) <span class="cpp-keyword">return</span> <span class="cpp-keyword">false</span>;<br>}<br><span class="cpp-keyword">return</span> <span class="cpp-keyword">true</span>;<br></pre></font></td></tr></table><!–ENDSCRIPT–><br><br>two subs + &#111;ne cross + &#111;ne dot per edge. Hardly a stretch for a processor. And it should be easy to really optimise the hell of it. And unrolling for triangles, …

Everything is better with Metal.

This topic is closed to new replies.

Advertisement