[vtkusers] vtkPointInTriangle - bug?

Dov Grobgeld dov.grobgeld at gmail.com
Tue Feb 18 15:11:30 EST 2014


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.

#!/usr/bin/python
from numpy import cross, dot, sqrtfrom numpy import array as Pimport vtk
def norm(v):
  mag = sqrt((v**2).sum())
  return v/mag

a,b,c = (P((0,0,0)),
         P((10,0,0)),
         P((10,10,0)))

p = P((5,1,1))
# Test for linearity##       b      #      / \#     /   \#    /  p  \#
  a-------c#
N1 = norm(cross(b-a, p-a))
N2 = norm(cross(p-c, b-c))
N1dotN2 = dot(N1,N2)print 'By norms: ', N1dotN2 > 0.99
# Same test with vtkprint 'vtkInTriangle = ',
vtk.vtkTriangle.PointInTriangle(p, a,b,c, 1e-10)

The result is:

 By norms:  False
vtkInTriangle =  1

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?

Thanks!
Dov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140218/67e761f6/attachment.html>


More information about the vtkusers mailing list