Saturday, June 21, 2008

Normal to Curve












Having hard time with
drawing normal (of the main spline) at each division point I ended up intersecting circle and offset splines. So when I first offset the main spline, I had to set offset tolerance high, at least more than default otherwise intersection fails.


'----------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------
Option Explicit
'Author: YukiukiH
'Date: 06/21/2008
'compatibility: Rhino4
'memo: watch arrPt and strPt

bridgeSt
Sub bridgeSt

'first things first...
Rhino.AddLayer "centerPt", RGB(0,0,0) 'black
Rhino.AddLayer "circle", RGB(105,105,105) 'darl gray
Rhino.AddLayer "normal01", RGB(255,161,0) 'gold
Rhino.AddLayer "normal02", RGB(255,127,0) 'orange
Rhino.AddLayer "Pt", RGB(0,0,0) 'black
Rhino.CurrentLayer ("centerPt")

'divide bridge spline into segments (by length or segments)
Dim strSpline, dblLength, intSegments
Dim strOffset01, strOffset02
Dim arrPts, arrPt, strCenPt

strSpline = Rhino.GetObject("Select a curve")
strOffset01 = Rhino.GetObject("Select the first offset curve")
strOffset02 = Rhino.GetObject("Select the second offset curve")
Call Rhino.LayerVisible ("splineCenter", False)
Call Rhino.LayerVisible ("splineOffset", False)

If Rhino.IsCurve(strSpline) Then
'by length segment
dblLength = 1500
arrPts = Rhino.DivideCurveLength(strSpline, dblLength)
'by segments
'intSegments = 130
'arrPoints = Rhino.DivideCurve(strSpline, intSegments)
For Each arrPt In arrPts
strCenPt = Rhino.AddPoint (arrPt)
Next
End If


'Ultimate Loop
'----------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------
Dim i, k
For i = 0 To UBound(arrPts)

'intersection (circle and offset spline) finds normal
Dim strCircle, arrPlane, arrInterPt01, arrInterPt02

arrPlane = Rhino.WorldXYPlane
strCircle = Rhino.AddCircle (arrPlane, 2000)
Call Rhino.ObjectLayer (strCircle, "circle")
Rhino.MoveObject strCircle, Array(0,0,0), arrPts(i)

Rhino.CurrentLayer ("Pt")
arrInterPt01 = Rhino.CurveCurveIntersection(strOffset01, strCircle)

If Not IsArray(arrInterPt01) Then
Rhino.Print "Selected curves do not intersect"
Exit Sub
End If

If arrInterPt01(k,0) = 1 Then
Rhino.Print "Intersection point on first curve: " & Rhino.Pt2Str(arrInterPt01(k,1))
Rhino.AddPoint arrInterPt01(k,1)
Else
Rhino.Print "Overlap"
Exit Sub
End If

arrInterPt02 = Rhino.CurveCurveIntersection(strOffset02, strCircle)
If Not IsArray(arrInterPt02) Then
Rhino.Print "Selected curves do not intersect"
Exit Sub
End If

If arrInterPt02(k,0) = 1 Then
Rhino.Print "Intersection point on first curve: " & Rhino.Pt2Str(arrInterPt02(k,1))
Rhino.AddPoint arrInterPt02(k,1)
Else
Rhino.Print "Overlap"
Exit Sub
End If

'add normal line
Dim strLine01, strLine02, strLine01axis, strLine02axis
Dim arrStPtLine01, arrStPtLine02, arrAxis01, arrAxis02
Dim strLine01vrt, strLine02vrt

Rhino.CurrentLayer ("normal01")
strLine01 = Rhino.AddLine (arrPts(i), arrInterPt01(k,1))
Rhino.CurrentLayer ("normal02")
strLine02 = Rhino.AddLine (arrPts(i), arrInterPt02(k,1))

Next
'----------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------

Call Rhino.LayerVisible ("splineCenter", True)
Call Rhino.LayerVisible ("splineOffset", True)
Call Rhino.print ("script complete")
End Sub