[vtkusers] Get normal vector of the closest polydata cell to a given test point

M. Jordan mjordan at live.at
Wed Jan 11 07:50:16 EST 2017

Thank you very much!

The problem is that most of the points are on the surface. Therefore test point = closest point.
I only use the cellLocator to get the corresponding cell.

Now I try to get the normale vector of the whole cell (orientation of the cell).

Is there a way to get that vector?

Von: Girish Lande <girish.lande at agiliad.com>
Gesendet: Mittwoch, 11. Jänner 2017 12:43
An: M. Jordan
Betreff: Re: [vtkusers] Get normal vector of the closest polydata cell to a given test point

Hi Jordan,

You can use vector between your test point and closest point as NORMAL vector.
Please see code snippet below.
normalizedX is output

double* pos = picker->GetPickPosition();

        double testPoint[3] = {pos[0],pos[1],pos[2]};

        //Find the closest points to TestPoint
        double closestPoint[3];//the coordinates of the closest point will be returned here
        double closestPointDist2; //the squared distance to the closest point will be returned here
        vtkIdType cellId; //the cell id of the cell containing the closest point will be returned here
        int subId; //this is rarely used (in triangle strips only, I believe)
        cellLocator->FindClosestPoint(testPoint, closestPoint, cellId, subId, closestPointDist2);

        std::cout << "Coordinates of closest point: " << closestPoint[0] << " " << closestPoint[1] << " " << closestPoint[2] << std::endl;
        std::cout << "Squared distance to closest point: " << closestPointDist2 << std::endl;
        std::cout << "CellId: " << cellId << std::endl;


// Compute a basis
         double normalizedX[3];
         double normalizedY[3];
         double normalizedZ[3];

         // The X axis is a vector from start to end
         vtkMath::Subtract(endPoint, startPoint, normalizedX);
         double length = vtkMath::Norm(normalizedX);

On 11 January 2017 at 16:32, M. Jordan <mjordan at live.at<mailto:mjordan at live.at>> wrote:


i have a test point p[x,y,z] and a polydata.
I use vtkCellLocator to get the closest cell of the polydata to this point.

I get:
- the closest point
- the squared distance to the closest point
- cell ID

Now I want to get the normal vector of the cell. I know the cell ID but I don't know how to get the
normal vector from it.

Thank you!

Powered by www.kitware.com<http://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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:

thanks & regards,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170111/a72bab30/attachment.html>

More information about the vtkusers mailing list