Curves and Surfaces

1 Curve and parameter

If a curve is given by the form C=C(t), the curve is called parametric curve.
C is the point at t or the (x,y,z) coordinate of the point at t.

1.png
Input: Crv a Curve
Input: t the parameter

Connect a slider to "t" slot.
Our first Python script for curves is,

import rhinoscriptsyntax as rs
a=rs.EvaluateCurve(Crv,t)

If min or max value of the slider is too small or too big, the obtained point may be out from the curve.
2.png 3.png 4.png

2 Curve domain

In order to ristrict the point to be between two ends of the curve, you need to get the domain of the curve.

domain=rs.CurveDomain(Crv) #Unpacking
if t<domain[0]:
    t=domain[0]
if t<domain[1]:
    t=domain[1]
a=rs.EvaluateCurve(Crv,t)

or using Unpacking, it is

(min,max)=rs.CurveDomain(Crv) #Unpacking
if t<min:
    t=min
if t>max:
    t=max
a=rs.EvaluateCurve(Crv,t)

3. Another way to avoid being nervous about domain

In most cases, programmer would prefer to set min/max of the slider to 0/1.
So, let's set min of the slider to 0 and max to 1.
In order to map 0 to the min of the domain and 1 to the max if the domain,
we use
T=min+(max-min)*t
The code should be,

import rhinoscriptsyntax as rs
(min,max)=rs.CurveDomain(Crv)
T=min+(max-min)*t
a=rs.EvaluateCurve(Crv,T)

rhinoscriptsyntax provides the same functionality by CurveParameter().

import rhinoscriptsyntax as rs
#(min,max)=rs.CurveDomain(Crv)
#T=min+(max-min)*t  #next line has same functionality as this line
T=rs.CurveParameter(Crv,t)
a=rs.EvaluateCurve(Crv,T)

CurveParameter() is frequently used.

4. Closest point to a curve

9.png
import rhinoscriptsyntax as rs
 
t=rs.CurveClosestPoint(Crv,P)
point=rs.EvaluateCurve(Crv,t)
line=rs.AddLine(P,point)
a=list()
a.append(point)
a.append(line)

10.png

5. Other important geometric properties

11.png
import rhinoscriptsyntax as rs
t=rs.CurveClosestPoint(Crv,P)
point=rs.EvaluateCurve(Crv,t)
line=rs.AddLine(P,point)
planeP=rs.CurvePerpFrame(Crv,t)
planeT=rs.CurveFrame(Crv,t)
V=rs.CurveTangent(Crv,t)
line2=rs.AddLine(point,point+V*20)
a=list()
a.append(point)
a.append(line)
a.append(line2)
a.append(planeP)
a.append(planeT)

12.png

6. Distributing points along a curve

5.png
import rhinoscriptsyntax as rs
N=20
a=list()
for i in range(N+1):
    T=rs.CurveParameter(Crv,i/N)
    a.append(rs.EvaluateCurve(Crv,T))

6.png

7. Equally distributing points along a curve

Because t is just a parameter it does not divide a curve evenly.
So, if you want to divide a curve equally, you need to use CurveArcLengthPoint().
7.png

import rhinoscriptsyntax as rs
N=20
a=list()
L=rs.CurveLength(Crv)
for i in range(N+1):
    point=rs.CurveArcLengthPoint(Crv,i/N*L)
    a.append(point)
8.png

8. Surface and parameter

13.png
Let's remain min/max of the sliders to 0/1.
For surfaces, SurfaceParameter is provided to fit the uv parameter to the domain of the surface.
import rhinoscriptsyntax as rs
(U,V)=rs.SurfaceParameter(Srf,(u,v))
point=rs.EvaluateSurface(Srf,U,V)
a=point

14.png

9. Extracting isocurves

If you fix v coordinate and only move u coordinate, the point will draw a tragectory. This is an isocurve of u direction.
15.png

import rhinoscriptsyntax as rs
(U,V)=rs.SurfaceParameter(Srf,(u,v))
point=rs.EvaluateSurface(Srf,U,V)
a=point
iU=rs.ExtractIsoCurve(Srf,(U,V),0)
iV=rs.ExtractIsoCurve(Srf,(U,V),1)

16.png

10. Closest point to a surface

21.png
import rhinoscriptsyntax as rs
a=list()
(U,V)=rs.SurfaceClosestPoint(Srf,P)
iU=rs.ExtractIsoCurve(Srf,(U,V),0)
iV=rs.ExtractIsoCurve(Srf,(U,V),1)
point=rs.EvaluateSurface(Srf,U,V)
line=rs.AddLine(P,point)
a.append(point)
a.append(line)

22.png

11. Local information of a surface

23.png
import rhinoscriptsyntax as rs
a=list()
(U,V)=rs.SurfaceClosestPoint(Srf,P)
iU=rs.ExtractIsoCurve(Srf,(U,V),0)
iV=rs.ExtractIsoCurve(Srf,(U,V),1)
plane=rs.SurfaceFrame(Srf,(U,V))
normal=rs.SurfaceNormal(Srf,(U,V))
point=rs.EvaluateSurface(Srf,U,V)
#line=rs.AddLine(P,point)
line2=rs.AddLine(point,point+normal*20)
a.append(point)
#a.append(line)
a.append(line2)
a.append(plane)

24.png

12. Distributing points onto a surface

25.png
import rhinoscriptsyntax as rs
a=list()
(U,V)=rs.SurfaceClosestPoint(Srf,P)
iU=rs.ExtractIsoCurve(Srf,(U,V),0)
iV=rs.ExtractIsoCurve(Srf,(U,V),1)
nU=10
nV=10
for i in range(nU+1):
    for j in range(nV+1):
        (U,V)=rs.SurfaceParameter(Srf,(i/nU,j/nV))
        plane=rs.SurfaceFrame(Srf,(U,V))
        normal=rs.SurfaceNormal(Srf,(U,V))
        point=rs.EvaluateSurface(Srf,U,V)
        line2=rs.AddLine(point,point+normal*20)
        a.append(point)
        a.append(line2)
        a.append(plane)

26.png