[vtkusers] vtkPointInTriangle - bug?

Dov Grobgeld dov.grobgeld at gmail.com
Wed Feb 19 01:47:33 EST 2014


Hi David,

Thanks for your reply. Three comments:

1. The documentation doesn't explain this is the behavior.
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 *not* be in the triangle
(a,b,c).
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?

Thanks!
Dov



On Tue, Feb 18, 2014 at 11:57 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> Hi Dov,
>
> The PointInTriangle method checks whether the point, after being
> projected onto the plane of the triangle, lies within the triangle.
>
>   David
>
> On Tue, Feb 18, 2014 at 1:11 PM, Dov Grobgeld <dov.grobgeld at gmail.com>
> wrote:
> > 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, sqrt
> > from numpy import array as P
> > import 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 vtk
> > print '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/20140219/a1e7cec0/attachment.html>


More information about the vtkusers mailing list