[vtkusers] Normals at intersection point

arwtyxouymz arw.tyx-ouy_mz at ezweb.ne.jp
Tue Aug 1 11:12:26 EDT 2017


Hi, all

I want to get normals at intersection point between ellipse and line.
I could get the intersection point, but I don't know how to get normals at
that point.
That part of My code is below.

Please help me!

========================================
    double angle = 0;
    double long_r, short_r;
    vtkIdType id = 0;
    double CenterX, CenterY, CenterZ;
    double z_length = 50.0;
    long_r = 50;
    short_r = 30;
    CenterX = 0.0; CenterY = 0.0, CenterZ = 0.0;

    vtkSmartPointer<vtkPoints> points =
            vtkSmartPointer<vtkPoints>::New();
    points->SetNumberOfPoints(2 * NUM_OF_DIVIDE);
    while (angle <= 2.0 * vtkMath::Pi() + (vtkMath::Pi() / NUM_OF_DIVIDE))
    {
        points->InsertPoint(id, long_r * cos(angle) + CenterX, short_r *
sin(angle) + CenterY, CenterZ);
        angle = angle + (vtkMath::Pi() / NUM_OF_DIVIDE);
        id++;
    }

    vtkSmartPointer<vtkPolyLine> line =
            vtkSmartPointer<vtkPolyLine>::New();
    line->GetPointIds()->SetNumberOfIds(id);
    for (int k = 0; k < id; ++k) {
        line->GetPointIds()->SetId(k, k);
    }

    vtkSmartPointer<vtkCellArray> lines =
            vtkSmartPointer<vtkCellArray>::New();
    lines->InsertNextCell(line);

    vtkSmartPointer<vtkPolyData> ellipse =
            vtkSmartPointer<vtkPolyData>::New();
    ellipse->GlobalReleaseDataFlagOff();
    ellipse->Allocate(1, 1);
    ellipse->SetPoints(points);
    ellipse->SetLines(lines);

    // 3次元化
    vtkSmartPointer<vtkLinearExtrusionFilter> extrude =
            vtkSmartPointer<vtkLinearExtrusionFilter>::New();
    extrude->SetInputData(ellipse);
    extrude->SetExtrusionTypeToNormalExtrusion();
    extrude->SetScaleFactor(1.0);
    extrude->SetVector(0, 0, z_length);
    extrude->Update();

    vtkSmartPointer<vtkTriangleFilter> triangles =
            vtkSmartPointer<vtkTriangleFilter>::New();
    triangles->SetInputConnection(extrude->GetOutputPort());
    triangles->Update();

    auto numberOfSubdivisions = 2;
    vtkSmartPointer<vtkLinearSubdivisionFilter> subdivision =
            vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
    subdivision->SetInputConnection(triangles->GetOutputPort());
    subdivision->SetNumberOfSubdivisions(numberOfSubdivisions);
    subdivision->Update();

    /////////////////// Omit ///////////////////////////

    double lineP0[3] = {TARGET_X, TARGET_Y, TARGET_Z};
    double lineP1[3] = {surfacePoints[minId][0] + directionVector[minId][0],
                        surfacePoints[minId][1] + directionVector[minId][1],
                        surfacePoints[minId][2] +
directionVector[minId][2]};
    vtkSmartPointer<vtkPoints> intersectPoints =
            vtkSmartPointer<vtkPoints>::New();
    vtkSmartPointer<vtkOBBTree> tree =
            vtkSmartPointer<vtkOBBTree>::New();
    tree->SetDataSet(subdivision->GetOutput());
    tree->BuildLocator();
    tree->IntersectWithLine(lineP0, lineP1, intersectPoints, NULL);
    std::cout << "NumPoints: " << intersectPoints->GetNumberOfPoints() <<
std::endl;
    double intersection[3];
    for (int i = 0; i < intersectPoints->GetNumberOfPoints(); i++)
    {
        intersectPoints->GetPoint(i, intersection);
        std::cout << "Intersection " << i << ":"
                  << intersection[0] << ", "
                  << intersection[1] << ", "
                  << intersection[2] << std::endl;
    }
====================================================



--
View this message in context: http://vtk.1045678.n5.nabble.com/Normals-at-intersection-point-tp5744238.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list