[vtkusers] Line polygon intersection
David Doria
daviddoria at gmail.com
Mon Feb 13 12:53:28 EST 2012
On Mon, Feb 13, 2012 at 12:09 PM, Jothybasu Selvaraj
<jothybasu at gmail.com> wrote:
> Why my ray(line) never intersects the polygon?
>
> I have a ray passing from up to down, and a polygon (like a circle at some
> depth around that line).
>
> Here is the code
>
> vtkSmartPointer<vtkPolygon> polygon =
>
> vtkSmartPointer<vtkPolygon>::New();
>
> polygon->GetPoints()->InsertNextPoint(-35.0, 91.0,7.5);
>
> polygon->GetPoints()->InsertNextPoint(47.0, 150.0, 7.5);
>
> polygon->GetPoints()->InsertNextPoint(47.0, 150.0,-57.0);
>
> polygon->GetPoints()->InsertNextPoint(-36.0, 92.0, -57.0);
>
> #polygon->GetPoints()->InsertNextPoint(-35.0, 91.0,7.5);//tried even
> closing the contour
>
> // Inputs
>
> double p1[3] = {-0.0,-884.0,-28.0};
>
> double p2[3] = {-0.0,187.0,-28.0};
>
> double tolerance = 0.001;
>
> // Outputs
>
> double t; // Parametric coordinate of intersection (0 (corresponding
> to p1) to 1 (corresponding to p2))
>
> double x[3]; // The coordinate of the intersection
>
> double pcoords[3];
>
> int subId;
>
>
> vtkIdType iD = polygon->IntersectWithLine(p1, p2, tolerance, t, x,
> pcoords, subId);
>
> // if(iD!=0)
>
> // {
>
> qDebug() << "iD: ";
>
> // }
There must be something wrong with your coordinates, or something
different in Python. This works as expected:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/PolygonIntersection
David
More information about the vtkusers
mailing list