PDA

View Full Version : Trim NURBS surface

gabriele.cuccolini
11-16-2016, 11:39 PM
Hi, I'm trying to visualize a trimmed NURBS surface with OPEN GL.

My surface is composed by a square on the plane XY with 10 mm of edge trimmed by a circle of radius 1. The geometries are centered in zero.

My sample of code is:

// vector containers for surface control points and knots
GLfloat surfacectrlpts[12] ={-5,-5,0,-5,5,0,5,-5,0,5,5,0};
GLfloat uKnots[4] = { 0,0,10,10 };
GLfloat vKnots[4] = { 0,0,10,10 };

theNurb = gluNewNurbsRenderer();

gluBeginSurface(theNurb);
gluNurbsSurface( theNurb, 4, &uKnots[0], 4, &vKnots[0], 6, 3, &surfacectrlpts[0], 2, 2, GL_MAP2_VERTEX_3 );

// Internal circle trim control points and knots
GLfloat trim_knots1[12] = {-6.2,-6.2,-6.2,-4.71239, -4.71239,-3.14159,-3.14159,-1.5708,-1.5708,0,0,0};
GLfloat trim_ctrlpts1[18] = {1,0,1,-1,0,-1,-1,-1,-1,0,-1,1,0,1,1,1,1,0};

gluBeginTrim(theNurb);
gluNurbsCurve(theNurb, 12, trim_knots1, 2, &trim_ctrlpts1[0], 3, GLU_MAP1_TRIM_2);
gluEndTrim(theNurb);

// External square trim control points and knots
GLfloat trim_knots2[7] = {0, 0, 10, 20, 30, 40, 40};
GLfloat trim_ctrlpts2[8] = {-5,-5,5,-5,5,5,-5,5};

gluBeginTrim(theNurb);
gluNurbsCurve(theNurb, 7, trim_knots2, 2, &trim_ctrlpts2[0], 2, GLU_MAP1_TRIM_2);
gluEndTrim(theNurb);

gluEndSurface(theNurb);

When I run my program on screen appear a wrong result. Only a quarter of the geometry appears and in a wrong position.
If I delete the lines about the trimming curves the single NURBS surface is visualized correctly. The data are imported from a simple IGES file.