[vtkusers] vtkPointInTriangle - bug?
David Gobbi
david.gobbi at gmail.com
Tue Feb 18 16:57:56 EST 2014
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
More information about the vtkusers
mailing list