<div dir="ltr">Hi Dov,<br><br>Looking at how vtkTriangle::PointInTriangle() is used in the VTK source ( in the vtkPolygon class) sheds some light as to why it is the way it is:<br><br><a href="http://vtk.org/gitweb?p=VTK.git;a=blob;f=Common/DataModel/vtkPolygon.cxx;h=5700038d14eb0fddf9b3884a46d1d1a268caae85;hb=HEAD#l1691">http://vtk.org/gitweb?p=VTK.git;a=blob;f=Common/DataModel/vtkPolygon.cxx;h=5700038d14eb0fddf9b3884a46d1d1a268caae85;hb=HEAD#l1691</a><br>
<br>(shorturl: <a href="http://goo.gl/SXpDHQ">http://goo.gl/SXpDHQ</a> )<br><br>To test for intersection between polygons, there's a cascade of increasingly more expensive tests:<br><br>vtkBox::IntersectBox()<br>vtkPlane::IntersectWithLine()<br>
vtkTriangle::PointInTriangle()<br><br>hth<br><br>Goodwin<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 19, 2014 at 6:47 AM, Dov Grobgeld <span dir="ltr"><<a href="mailto:dov.grobgeld@gmail.com" target="_blank">dov.grobgeld@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi David,<br><br>Thanks for your reply. Three comments:<br>
<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">
1. The documentation doesn't explain this is the behavior.<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">2. Projected by what direction. I would assume by the direction of the triangle normal. But this is not consistant with testing p=P((5,1,10)) in the below script which is reported by vtk to <b>not</b> be in the triangle (a,b,c).<br>
</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">3. Could this behavior be related to my other reported bug in vtkCellLocator.FindCell() that return the ''wrong" vtkTriangle, which does not contain the queried point?<br>
<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks!<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">
Dov<br><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Feb 18, 2014 at 11:57 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Dov,<br>
<br>
The PointInTriangle method checks whether the point, after being<br>
projected onto the plane of the triangle, lies within the triangle.<br>
<span><font color="#888888"><br>
David<br>
</font></span><div><div><br>
On Tue, Feb 18, 2014 at 1:11 PM, Dov Grobgeld <<a href="mailto:dov.grobgeld@gmail.com" target="_blank">dov.grobgeld@gmail.com</a>> wrote:<br>
> The following is a comparison of testing whether a point p falls within the<br>
> plane of a triangle a,b,c by basic python code vs by using vtk.<br>
><br>
> #!/usr/bin/python<br>
><br>
> from numpy import cross, dot, sqrt<br>
> from numpy import array as P<br>
> import vtk<br>
><br>
> def norm(v):<br>
> mag = sqrt((v**2).sum())<br>
> return v/mag<br>
><br>
> a,b,c = (P((0,0,0)),<br>
> P((10,0,0)),<br>
> P((10,10,0)))<br>
><br>
> p = P((5,1,1))<br>
><br>
> # Test for linearity<br>
> #<br>
> # b<br>
> # / \<br>
> # / \<br>
> # / p \<br>
> # a-------c<br>
> #<br>
> N1 = norm(cross(b-a, p-a))<br>
> N2 = norm(cross(p-c, b-c))<br>
> N1dotN2 = dot(N1,N2)<br>
> print 'By norms: ', N1dotN2 > 0.99<br>
><br>
> # Same test with vtk<br>
> print 'vtkInTriangle = ', vtk.vtkTriangle.PointInTriangle(p, a,b,c, 1e-10)<br>
><br>
> The result is:<br>
><br>
> By norms: False<br>
> vtkInTriangle = 1<br>
><br>
> It is trivial that the point p does not fall in the triangle. But still vtk<br>
> sais so. Is this a bug in vtk or am I misunderstanding what<br>
> vtkTriangle.PointInTriangle() is doing?<br>
><br>
> Thanks!<br>
> Dov<br>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>