Some Basic Surfaces 2

Translational Surface

We start with a GhPython component places in a GH canvas.

Curves and basic rhinoscriptsyntax commands

Set up the GhPython component placed with the following inputs:

  • C : ghdoc Object when geometry

Connect a Curve parameter with the input parameter 'C'.
01.png
02.png
Then, try

import rhinoscriptsyntax as rs
domain=rs.CurveDomain(C)
print domain

You may get
|[0.0, 91.645558482449374]
The values may vary according to your configuration.
This means that, if the curve is parameterized by t, t moves from 0 to 91.645.
A point on a curve which is specified by t is obtained by using rs.EvaluateCurve().
Let's try
import rhinoscriptsyntax as rs
domain=rs.CurveDomain(C)
print domain
t=10
a=rs.EvaluateCurve(C,t)

Then, try changing the parameter 't'.
03.png
import rhinoscriptsyntax as rs
domain=rs.CurveDomain(C)
print domain
t=rs.CurveParameter(C,0.5)
a=rs.EvaluateCurve(C,t)

Now, let's see how evenly distributed 't' arrange points along the curve.
import rhinoscriptsyntax as rs
domain=rs.CurveDomain(C)
print domain
a=list()
for T in rs.frange(0,1.0,0.1):
    t=rs.CurveParameter(C,T)
    a.append(rs.EvaluateCurve(C,t))
#    T2=rs.CurveNormalizedParameter(C,t)
#    print str(T)+"  "+str(T2)

Note that rs.CurveNormalizedParameter() has the inverse functionality as rs.CurveParameter().
04.png
It looks that the arc-length between the points are not the same.
In other words, arc-length and parameter t are very different.
import rhinoscriptsyntax as rs
domain=rs.CurveDomain(C)
print domain
a=list()
for T in rs.frange(0,1.0,0.1):
    p=rs.CurveArcLengthPoint(C,T*80)
    a.append(p)

05.png
Note that now they are evenly distributed in arc-length.

if, elif, else and while statements

Let's add 't' as an input parameter of the GhPython component.
Let's specify 'T' as a float number.
Plus, connect a slider which range is 0.0-1.0 with 'T'
06.png

import rhinoscriptsyntax as rs
if T<0:
    T=0
elif T>1:
    T=1
else:
    pass
t=rs.CurveParameter(C,T)
a=rs.EvaluateCurve(C,t)

07.png

Now, we introduce a while statement.

import rhinoscriptsyntax as rs
if T<0:
    T=0
elif T>1:
    T=1
else:
    pass
t=rs.CurveParameter(C,T)
#totalLength=rs.CurveLength()
#print totalLength
Length=rs.CurveLength(C,-1,(0,t))
bitLength=Length/10
currentLength=0
a=list()
while currentLength<=Length:
    p=rs.CurveArcLengthPoint(C,currentLength)
    a.append(p)
    currentLength+=bitLength

08.png

Now, let's eliminate 't' and add 'P' for input parameters.
Connect a point parameter with 'P'.
09.png

import rhinoscriptsyntax as rs
 
t=rs.CurveClosestPoint(C,P)
a=rs.EvaluateCurve(C,t)

You can get the closest point on the curve from the specified point.
10.png
Again, let's try using while statement like
import rhinoscriptsyntax as rs
 
t=rs.CurveClosestPoint(C,P)
Length=rs.CurveLength(C,-1,(0,t))
bitLength=Length/10
currentLength=0
a=list()
while currentLength<Length:
    p=rs.CurveArcLengthPoint(C,currentLength)
    a.append(p)
    currentLength+=bitLength

You may get
11.png

Translational Surface

Set up your ghPython component with the following input parameters:

  • C1: ghdoc Object if geometry
  • C2: ghdoc Object if geometry

Then connect two curves parameters with C1 and C2.
Make sure to let the starting points of the C1 and C2 meet at the same point.
12.png
14.png

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
if rs.CurveStartPoint(C1)==rs.CurveStartPoint(C2):
    print "OK"
else:
    print "BAD"

Then let's extend the GhPython coponent. First set up it with the following input parameters:
  • C1: ghdoc Object if geometry
  • C2: ghdoc Object if geometry
  • u: float
  • v: float

Then, connect two sliders (float) with u and v.
Our next script code is

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
if rs.CurveStartPoint(C1)==rs.CurveStartPoint(C2):
    print "OK"
    a=list()
    for i in rs.frange(0,1.0,0.1):
        t=rs.CurveParameter(C1,u*i)
        p=rs.EvaluateCurve(C1,t)
        a.append(p)
    for i in rs.frange(0,1.0,0.1):
        t=rs.CurveParameter(C2,v*i)
        p=rs.EvaluateCurve(C2,t)
        a.append(p)
else:
    print "BAD"

Then, you get
13.png
Then, rewrite the script as follows
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
if rs.CurveStartPoint(C1)==rs.CurveStartPoint(C2):
    print "OK"
    T1=rs.CurveStartPoint(C1)
    a=list()
    for i in rs.frange(0,1.0,0.1):
        for j in rs.frange(0,1.0,0.1):
            tu=rs.CurveParameter(C1,u*i)
            pu=rs.EvaluateCurve(C1,tu)
            tv=rs.CurveParameter(C2,v*j)
            pv=rs.EvaluateCurve(C2,tv)
            P=pu+(pv-T1)
            a.append(P)
else:
    print "BAD"

Then you may get
15.png

Building a mesh

Let's build a mesh which is based on the previous result.
For this aim, the code below is inserted.

    Faces=list()
    for i in range(10):
        for j in range(10):
            Faces.append(
            (i+j*11,        i+1+j*11,
             i+1+(j+1)*11,  i+(j+1)*11))
    M=rs.AddMesh(a,Faces)
[[/code]
The whole code is as follows:
[[code type="Python"]]
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
if rs.CurveStartPoint(C1)==rs.CurveStartPoint(C2):
    print "OK"
    T1=rs.CurveStartPoint(C1)
    a=list()
    for i in rs.frange(0,1.0,0.1):
        for j in rs.frange(0,1.0,0.1):
            tu=rs.CurveParameter(C1,u*i)
            pu=rs.EvaluateCurve(C1,tu)
            tv=rs.CurveParameter(C2,v*j)
            pv=rs.EvaluateCurve(C2,tv)
            P=pu+(pv-T1)
            a.append(P)
    Faces=list()
    for i in range(10):
        for j in range(10):
            Faces.append(
            (i+j*11,        i+1+j*11,
             i+1+(j+1)*11,  i+(j+1)*11))
    M=rs.AddMesh(a,Faces)
else:
    print "BAD"

The mesh created is visualized like
16.png