Problem in Creating a Nurbs Surface

Hello! everyone, I am trying to create a nurbs surface with 4x5 control points .but the result was never shown,I do not know what the problem is? Thanks

//Joann

CRhinoCommand::result CCommandPlugIn1::RunCommand(const CRhinoCommandContext& context)
{
	   int u_degree = 3;
	   int v_degree = 3;
		 
	   int u_order = u_degree + 1;
	   int v_order = v_degree + 1;

           int cu_count = 4;
           int cv_count = 5;
	
	 ON_NurbsSurface nurbs = ON_NurbsSurface(3, FALSE, u_order, v_order, cu_count, cv_count);

	       nurbs.SetCV(0, 0, ON_3dPoint(512.0, 235.0, 419.0));
	       nurbs.SetCV(0, 1, ON_3dPoint(502.0, 220.0, 430.0));
	       nurbs.SetCV(0, 2, ON_3dPoint(487.0, 213.0, 399.0));
	       nurbs.SetCV(0, 3, ON_3dPoint(489.0, 231.0, 409.0));

	       nurbs.SetCV(1, 0, ON_3dPoint(519.0, 269.0, 423.0));
	       nurbs.SetCV(1, 1, ON_3dPoint(539.0, 235.0, 412.0));
	       nurbs.SetCV(1, 2, ON_3dPoint(590.0, 290.0, 400.0));
	       nurbs.SetCV(1, 3, ON_3dPoint(611.0, 213.0, 399.0));

		   nurbs.SetCV(2, 0, ON_3dPoint(560.0, 288.0, 180.0));
		   nurbs.SetCV(2, 1, ON_3dPoint(555.0, 298.0, 170.0));
		   nurbs.SetCV(2, 2, ON_3dPoint(571.0, 271.0, 169.0));
		   nurbs.SetCV(2, 3, ON_3dPoint(580.0, 281.0, 179.0));

		   nurbs.SetCV(3, 0, ON_3dPoint(621.0, 213.0, 340.0));
		   nurbs.SetCV(3, 1, ON_3dPoint(658.0, 256.0, 319.0));
		   nurbs.SetCV(3, 2, ON_3dPoint(627.0, 298.0, 391.0));
		   nurbs.SetCV(3, 3, ON_3dPoint(672.0, 289.0, 309.0));

		   nurbs.SetCV(4, 0, ON_3dPoint(701.0, 312.0, 491.0));
		   nurbs.SetCV(4, 1, ON_3dPoint(753.0, 356.0, 402.0));
		   nurbs.SetCV(4, 2, ON_3dPoint(739.0, 399.0, 482.0));
		   nurbs.SetCV(4, 3, ON_3dPoint(759.0, 389.0, 472.0));

	           nurbs.SetKnot(0, 0, 235.0);
	           nurbs.SetKnot(0, 1, 213.0);
	           nurbs.SetKnot(0, 2, 271.0);
		   nurbs.SetKnot(0, 3, 357.0);
		   nurbs.SetKnot(0, 4, 371.0);
		   nurbs.SetKnot(0, 5, 399.0);
		  
	           nurbs.SetKnot(1, 0, 199.0);
		   nurbs.SetKnot(1, 1, 153.0);
		   nurbs.SetKnot(1, 2, 188.0);
		   nurbs.SetKnot(1, 3, 120.0);
		   nurbs.SetKnot(1, 4, 169.0);
		   nurbs.SetKnot(1, 5, 181.0);
		   nurbs.SetKnot(1, 6, 200.0);
		   
		   if (nurbs.IsValid())
		   {
		     context.m_doc.AddSurfaceObject(nurbs);
		     context.m_doc.Redraw();
		   }

return CRhinoCommand::success;
}

You might want to add an “else” to this:

else
print “nurbs is invalid” (well, not literally, just whatever it takes in your language/environment to get a console output or screen display)

just to confirm it’s good.

Hi @15951991225,

Modify the bottom of your function to look like this:

ON_wString log_string;
ON_TextLog log(log_string);
if (nurbs.IsValid(&log))
{
  context.m_doc.AddSurfaceObject(nurbs);
  context.m_doc.Redraw();
}
else
{
  RhinoApp().Print(L"%s\n", static_cast<const wchar_t*>(log_string));
}

Now when you run your test command, you will see this output on the command line:

Knot vector must be increasing but knot[0]=235 > knot[1]=213
ON_NurbsSurface.m_knot[0] is not a valid knot vector.

Please review the “Knots” section in the following guide.

https://developer.rhino3d.com/guides/rhinopython/python-rhinoscriptsyntax-nurbs/

– Dale

Thanks! Dale. The reason is that I didn’t understand the knot vector. I will study the the guide.

_Joann

Thanks! AIW. I got it.