Create a NURBS surface

I try to model a NURBS surface with Grasshopper.

For that, I wrote a Python script but I don’t see how to modify the knot vectors (I can insert values but not remove them, the function rs.RemoveSurfaceKnot returns “False”, maybe because I don’t give the right values).


import copy
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg

for i in range(len(points)):
    points[i] = rs.coerce3dpoint(points[i])

surface = rg.NurbsSurface.CreateFromPoints(points, uCount, vCount, uDegree, vDegree)

for k in surface.KnotsU:
    rs.RemoveSurfaceKnot(surface, (k, 0), False)

for k in surface.KnotsV:
    rs.RemoveSurfaceKnot(surface, (0, k), True)

for k in knotsU:
    surface.KnotsU.InsertKnot(k)

for k in knotsV:
    surface.KnotsV.InsertKnot(k)

for k in surface.KnotsU:
    print(k)

The “print” display the new inserted values with previous values that I can’t remove.

Is there any way to do what I want?

Thanks and regards,

Julien

The KnotsU and KnotsV members of the surface object are indexed:

k = surface.Knots[3] # read  value of 4th knot
surface.KnotsU[3] = k*2 # write value to 4th knot

I try it but without success.
In my case, surface.KnotsU is the vector [0, 0, 0, 0, 1, 2, 2, 2, 2] (9-size) and I want to put the vector [0, 0, 0, 0, 0.25, 0.5, 0.75, 1, 1, 1, 1] (11-size).

The number of knots is not free to choose, this depends on the surface degree and number of control points: nKnots = nControlPoints + degree - 1
So if you want to have a U-knot vector of length 11, you need to add two more control point rows in the surface U-direction. This is easiest done by calling InsertKnot, as that will add new and modify existing control points to keep the surface shape the same with more control points.

Yes of course but I have 6x6 grid points with degree of 4 for u and v, so 11-size for knot vectors, so I don’t understand why the size is 9.
nurbs_surface.gh (10.0 KB)
Here is my GH file, it can help.

I think you have come across a difference between the opennurbs convention of number of knots and the number of knots that is used in many textbooks on NURBS and other programs. opennurbs does not have what is called “superfluous” knots. For more info see Rhino - Superfluous Knots

So, by after construction of the surface you will have a knot vector in both directions of length (order + nCV - 2) = (5+6-2) = 9

U - [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 2.0, 2.0]
V - [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 2.0, 2.0]

Now, what is the reason you want to have [0, 0, 0, 0, 0.25, 0.5, 0.75, 1, 1, 1, 1], can you tell me more so I can understand what problem it is you’re trying to solve.

I want to compare geodl and Rhino features. The input data is just an example.
The formula is not m = n + p + 1 like in NURBS-Python/geomdl/knotvector.py at 5.x · orbingol/NURBS-Python · GitHub line 123 ?

Hi @Julien_Livet,

Correct. Rhino does not carry around the extra (superfluous) knots.

– Dale

Ok, I understand, thanks!

Here is an extra question: if I want to put some weights on my control points, how do I do? I saw this topic but I don’t arrive to apply it: Creating nurbs surface using degree, control points, knots and weights - #10 by ivelin.peychev.

Hi @Julien_Livet,

If you have a NURBS surface, then you will want to make sure it’s rational. If not, then make it rational.

Now that you have a rational NURBS surfaces, you can just set the control point weights.

– Dale