[vtkusers] IntersectWithLine returns wrong pcoords?

Alexander Pletzer alexander.pletzer at nesi.org.nz
Thu Aug 24 20:10:54 EDT 2017


Hi,

The simple python code below seems to return the wrong parametric
coordinates (if I understand correctly what they mean). This is with python
2.7 and VTK 6.3.

I'm creating a hex cell representing a unit cube [0, 1]^3. Then I create a
ray with start/end points pA and pB respectively. The code finds the
intersection between the ray and the cell, and the intersection point (0,
0.4, 0.3) looks right. However, I'm getting

[0.30000000000000004, 0.0, -1.0]

for the parametric coordinates -- I expected [0., 0.4, 0.3]. Shouldn't the
pcoords be between 0 and 1? Why is the last pcoords not set?

Thanks in advance for any help.

--Alex

import vtk

cell = vtk.vtkHexahedron()

pts = cell.GetPoints()
pts.InsertPoint(0, 0., 0., 0.)
pts.InsertPoint(1, 1., 0., 0.)
pts.InsertPoint(2, 1., 1., 0.)
pts.InsertPoint(3, 0., 1., 0.)
pts.InsertPoint(4, 0., 0., 1.)
pts.InsertPoint(5, 1., 0., 1.)
pts.InsertPoint(6, 1., 1., 1.)
pts.InsertPoint(7, 0., 1., 1.)

pA = [-0.5, 0.4, 0.3]
pB = [ 0.5, 0.4, 0.3]

t = vtk.mutable(0.0)
intersectPt = [-1.0, -1.0, -1.0]
pcoords = [-1.0, -1.0, -1.0]
subId = vtk.mutable(-1)
tol = 1.e-10

res = cell.IntersectWithLine(pA, pB, tol, t, intersectPt, pcoords, subId)

if res:
    print 'found intersection at ', intersectPt
    print 'line parametric coord: ', t, ' cell parametric coords: ',
pcoords, ' expected: ', [0., 0.4, 0.3], ' subId = ', subId


-- 
Alexander Pletzer
HPC Scientific Programmer for New Zealand eScience Infrastructure (NeSI)
National Institute of Water and Atmospheric Research (NIWA)
301 Evans Bay Parade, Hataitai, Wellington 6021, New Zealand
mobile: +64 21 085 79661
http://www. <http://www.niwa.co.nz>nesi.org.nz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170825/4fcec24b/attachment.html>


More information about the vtkusers mailing list