[vtkusers] vtkPointInTriangle - bug?

Goodwin Lawlor goodwin.lawlor.lists at gmail.com
Wed Feb 19 13:39:43 EST 2014


Hi Dov,

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:

http://vtk.org/gitweb?p=VTK.git;a=blob;f=Common/DataModel/vtkPolygon.cxx;h=5700038d14eb0fddf9b3884a46d1d1a268caae85;hb=HEAD#l1691

(shorturl: http://goo.gl/SXpDHQ )

To test for intersection between polygons, there's a cascade of
increasingly more expensive tests:

vtkBox::IntersectBox()
vtkPlane::IntersectWithLine()
vtkTriangle::PointInTriangle()

hth

Goodwin


On Wed, Feb 19, 2014 at 6:47 AM, Dov Grobgeld <dov.grobgeld at gmail.com>wrote:

> 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
>>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140219/7930d9dd/attachment.html>


More information about the vtkusers mailing list