Curvature and Text Tags

1. Text Tag

At first, we use the pure Python editor instead of GHPython in the Grasshopper environment.
On the command prompt of Rhino, type "EditPythonScript" and hit Enter.
Then Rhino Python Editor will open.
Type

import rhinoscriptsyntax as rs
rs.AddText("Hello",(0,0,0))

and run.

You get
1.png

HOWEVER, if you test

import rhinoscriptsyntax as rs
a=rs.AddText("Hello",(0,0,0))

with a GHPython component in the Grasshopper environment, you get
|Runtime error (NotSupportedException): This call is not supported from within a Grasshopper component
|Traceback:
| line 130, in AddText, "C:\Users\Masaaki\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\geometry.py"
| line 2, in script

As we have seen above, AddText() and AddTextDot() cannot be called from inside the Grasshopper environment.

So here is an alternative way to add TextObject with GhPython.
First, you can find a Text Tag component in the Point Group of Vector Tab.
Set up a GhPython component and a Text Tag component like this.
2.png
Then, a text and the location are output separately.

import rhinoscriptsyntax as rs
Text="Hello"
Center=rs.AddPoint(0,0,0)

You get
3.png

Here is another option. Because Text Tag component does not consider the size of texts, in most cases Text Tag3D component is preferably used.
4.png

import rhinoscriptsyntax as rs
Text="Hello"
Center=rs.AddPoint(0,0,0)

5.png

2. Distributing texts along a curve

6.png
import rhinoscriptsyntax as rs
Text=list()
Center=list()
N=10
for i in range(N+1):
    t=rs.CurveParameter(x,i/N)
    P=rs.EvaluateCurve(x,t)
    Center.append(P)
    text=str(t)
    #text="%5.2f" % t  #formatting text will be explained in another lecture
    Text.append(text)

7.png

3. Distributing texts onto a surface

8.png
import rhinoscriptsyntax as rs
Text=list()
Center=list()
N=10
for i in range(N+1):
    for j in range(N+1):
        (u,v)=rs.SurfaceParameter(x,(i/N,j/N))
        P=rs.EvaluateSurface(x,u,v)
        Center.append(P)
        text="["+str(u)+","+str(v)+"]"
        #text="[%5.2f,%5.2f]" % (u,v)  #formatting text will be explained in another lecture
        Text.append(text)

9.png

What is curvature?

22.png
23.png

4. Approximating a curve by circle

This is our setup.
10.png
The ranges:
t1: -1 to 0
t2: 0 to 1
t3: 0 to 1

import rhinoscriptsyntax as rs
a=list()
T1=rs.CurveParameter(x,t2+t1)
T2=rs.CurveParameter(x,t2)
T3=rs.CurveParameter(x,t2+t3)
P1=rs.EvaluateCurve(x,T1)
P2=rs.EvaluateCurve(x,T2)
P3=rs.EvaluateCurve(x,T3)
circle=rs.AddCircle3Pt(P1,P2,P3)
a.append(circle)
a.append(P1)
a.append(P2)
a.append(P3)
Center=P2
Text=str(rs.CircleRadius(circle))

If you set t1 and t3 very close to 0, the circle would become a good approximation of a tiny element of the curve at t2.
Also, we output curvature radius.
If you invert the curvature radius, it is the curvature at t2.
11.png

5. Using rhinoscriptsyntax 1

You can use rs.CurveRadius() to get the curvature radius.
12.png

import rhinoscriptsyntax as rs
a=list()
T=rs.CurveParameter(x,t)
P=rs.EvaluateCurve(x,T)
R=rs.CurveRadius(x,P)
a.append(P)
Center=P
Text=str(R)
13.png

6. Using rhinoscriptsyntax 2

You can also use rs.CurveCurvature() to get further information about curvature.
14.png

import rhinoscriptsyntax as rs
a=list()
T=rs.CurveParameter(x,t)
(P,V,C,R,K)=rs.CurveCurvature(x,T)
a.append(P)
a.append(C)
a.append(rs.AddLine(P,P+V))
a.append(rs.AddLine(P,C))
Center=P
Text="Radius:"+str(R)+" Curvature:"+str(rs.VectorLength(K))

P is the point, V is the tangent vector, C is the center of the curvature Radius, R is the curvature radiuis and K is the vector parallel to the vector from P to C but having its length as curvature (not curvature radius).
15.png

7. Displaying curvatures on a curve

16.png
import rhinoscriptsyntax as rs
import math
a=list()
Center=list()
Text=list()
N=10
for i in range(N+1):
    T=rs.CurveParameter(x,i/N)
    (P,V,C,R,K)=rs.CurveCurvature(x,T)
    a.append(P)
    Center.append(P)
    Text.append("R:"+str(round(R,2))+" K:"+str(round(rs.VectorLength(K),2)))

17.png

8. Curvature on surface

Because surface is two dimensional, there are many quantities that represent curvature on a surface.
18.png

import rhinoscriptsyntax as rs
a=list()
(U,V)=rs.SurfaceParameter(x,(u,v))
(P,N,K1,V1,K2,V2,K,H)=rs.SurfaceCurvature(x,(U,V))
a.append(P)
a.append(rs.AddLine(P,P+V1))
a.append(rs.AddLine(P,P+V2))
Center=P
Text="K:"+str(round(K,3))+" H:"+str(round(H,3))
print K1
print K2

P is the point, N is the normal vector, K1 is the maximum principal curvature, V1 is the tangent vector which point the first principal direction, K2 is the minimum principal curvature, V2 is the tangent vector which point the second principal direction, K is the Gaussian curvature (K1*K2) and H is the mean curvature ((K1+K2)/2))
19.png

9. Curvature radius on a surface

20.png
import rhinoscriptsyntax as rs
import math
a=list()
(U,V)=rs.SurfaceParameter(x,(u,v))
(P,N,K1,V1,K2,V2,K,H)=rs.SurfaceCurvature(x,(U,V))
a.append(P)
a.append(rs.AddLine(P,P+V1))
a.append(rs.AddLine(P,P+V2))
Center=P
plane1=rs.PlaneFromFrame(P+rs.VectorScale(N,1/K1),N,V1)
plane2=rs.PlaneFromFrame(P+rs.VectorScale(N,1/K2),N,V2)
a.append(rs.AddCircle(plane1,math.fabs(1/K1)))
a.append(rs.AddCircle(plane2,math.fabs(1/K2)))
Text="K:"+str(round(K,3))+" H:"+str(round(H,3))
print K1
print K2

21.png