NURBS surfaces


Geometric definition


A NURBS surface is a surface parametrized by points. It can be planar but is most often curved in at least one direction. Getting into the nitty gritty of NURBS is outside the scope of this cource, but your favourite online encyclopedia has a rather complete page on NURBS.

How to add


RhinoCommons


Here are two ways you can create NURBS surfaces with RhinoCommons:

import Rhino 
import scriptcontext as sc

# Points needed to create the NURBS surface
point_A = Rhino.Geometry.Point3d(0, 0, 20)
point_B = Rhino.Geometry.Point3d(0, 20, 0)
point_C = Rhino.Geometry.Point3d(20, 0, 0)
point_D = Rhino.Geometry.Point3d(20, 20, 20)

# Will create a NURBS surface from 4 corner points
my_surface = Rhino.Geometry.NurbsSurface.CreateFromCorners(point_A, 
                                                           point_B, 
                                                           point_C, 
                                                           point_D, 
                                                           tolerance = sc.doc.ModelAbsoluteTolerance)
sc.doc.Objects.AddSurface(my_surface)


import Rhino 
import scriptcontext as sc

# Curves in the u and v directions needed to create the NURBS surface
crvs = [curve_u_1, curve_u_2, curve_v_1, curve_v_2]

# Will create a NURBS surface passing through a network of curves in two directions
my_surface = Rhino.Geometry.NurbsSurface.CreateNetworkSurface(crvs, 
                                                              continuity=0, 
                                                              edgeTolerance= sc.doc.ModelAbsoluteTolerance, 
                                                              interiorTolerance= sc.doc.ModelAbsoluteTolerance,
                                                              angleTolerance= sc.doc.ModelAngleToleranceRadians)[0]

sc.doc.Objects.AddSurface(my_surface)

Rhinoscriptsyntax


import rhinoscriptsyntax as rs

# getting the curves needed to create the NURBS surface
crvs = rs.GetObjects("Select the curves in u and v directions",
                     filter=4, 
                     select=True, 
                     maximum_count = 50)

# Will create a NURBS surface passing through a network of curves in two directions
rs.AddNetworkSrf(crvs)

Main methods and properties:


Methods


# Will evaluate the point on the surface at local coordinates u,v.
u = 1
v = 2
my_surface.PointAt(u, v)

# Will evaluate the normal on the surface at local coordinates u,v.
u = 1
v = 2
my_surface.NormalAt(u, v)


test_point = Rhino.Geometry.Point3d(0, 0, 0)

# Will evaluate the u, v local coordinates on the surface that are the closest to the test_point
res, u, v = my_surface.ClosestPoint(test_point)

print(u, v)

Properties


# Will return the list of control points of the NURBS surface:

my_surface.Points

# Can be used to modify the control points:

control_point = my_surface.Points.GetControlPoint(1, 1)

control_point.X = 100
control_point.Y = 100
control_point.Z = 100

my_surface.Points.SetControlPoint(1, 1, control_point)


🛠 Exercise


01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 01: 🦏⬇️⬇️⬇️ Download the 3dm here ⬇️⬇️⬇️🦏 02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍

Solution:

01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍