[vtkusers] Line polygon intersection

Jothybasu Selvaraj jothybasu at gmail.com
Mon Feb 13 12:09:33 EST 2012


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: ";

//    }



Thanks

Jothy



On Mon, Feb 13, 2012 at 2:27 PM, David Doria <daviddoria at gmail.com> wrote:

> On Mon, Feb 13, 2012 at 9:25 AM, Jothybasu Selvaraj <jothybasu at gmail.com>
> wrote:
> > Thanks David,
> >
> > But vtkPolygon::PointInPolygon, I can only define the point of interest,
> to
> > check whether it is inside the given polygon or not. I want to define the
> > starting and end points of the ray and find whether it intersects a 2D
> > polygon, the ray will pass through the polygon in any 3D angle.
> >
> > I will try the BSP tree.
> >
> > Jothy
>
> The link I sent was to int vtkPolygon::IntersectWithLine, which should
> do exactly what you are asking.
>



-- 
Jothy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120213/34229c6b/attachment.htm>


More information about the vtkusers mailing list