<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">The following is a comparison of testing whether a point p falls within the plane of a triangle a,b,c by basic python code vs by using vtk. <br>
<div class="">
<pre class=""><span style="color:rgb(178,34,34)">#</span><span style="color:rgb(178,34,34)">!/usr/bin/python</span>
<span style="color:rgb(160,32,240)">from</span> numpy <span style="color:rgb(160,32,240)">import</span> cross, dot, sqrt
<span style="color:rgb(160,32,240)">from</span> numpy <span style="color:rgb(160,32,240)">import</span> array <span style="color:rgb(160,32,240)">as</span> P
<span style="color:rgb(160,32,240)">import</span> vtk
<span style="color:rgb(160,32,240)">def</span> <span style="color:rgb(0,0,255)">norm</span>(v):
mag = sqrt((v**2).sum())
<span style="color:rgb(160,32,240)">return</span> v/mag
a,b,c = (P((0,0,0)),
P((10,0,0)),
P((10,10,0)))
p = P((5,1,1))
<span style="color:rgb(178,34,34)"># </span><span style="color:rgb(178,34,34)">Test for linearity</span>
<span style="color:rgb(178,34,34)">#</span>
<span style="color:rgb(178,34,34)"># </span><span style="color:rgb(178,34,34)">b </span>
<span style="color:rgb(178,34,34)"># </span><span style="color:rgb(178,34,34)">/ \</span>
<span style="color:rgb(178,34,34)"># </span><span style="color:rgb(178,34,34)">/ \</span>
<span style="color:rgb(178,34,34)"># </span><span style="color:rgb(178,34,34)">/ p \</span>
<span style="color:rgb(178,34,34)"># </span><span style="color:rgb(178,34,34)">a-------c</span>
<span style="color:rgb(178,34,34)">#</span>
N1 = norm(cross(b-a, p-a))
N2 = norm(cross(p-c, b-c))
N1dotN2 = dot(N1,N2)
<span style="color:rgb(160,32,240)">print</span> <span style="color:rgb(0,139,0)">'By norms: '</span>, N1dotN2 > 0.99
<span style="color:rgb(178,34,34)"># </span><span style="color:rgb(178,34,34)">Same test with vtk</span>
<span style="color:rgb(160,32,240)">print</span> <span style="color:rgb(0,139,0)">'vtkInTriangle = '</span>, vtk.vtkTriangle.PointInTriangle(p, a,b,c, 1e-10)
<br></pre><pre class="">The result is:<br></pre>
</div>
<pre class="">By norms: False
vtkInTriangle = 1
</pre>It is trivial that the point p does not fall in the triangle. But still vtk sais so. Is this a bug in vtk or am I misunderstanding what vtkTriangle.PointInTriangle() is doing? <br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">
Thanks!<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Dov<br><br></div><div style id="divCleekiAttrib"></div><div style id="divCleekiAttrib"></div><div style id="divCleekiAttrib"></div>
<div style id="divCleekiAttrib"></div></div>