090918-geometry study 2

Squeeze Flower

This one comes from playing with clay. By stretching and pulling, the clay will form growing leaves shape. Here is the code to generate that.

Option Explicit
‘Script written by Shuang Xu

‘Script copyrighted by <insert company name>
‘Script version 2009年9月16日 9:41:29

Call Main()
Sub Main()
 Dim strcurve,number,i,arrdivpt,radius,length,offset,factor
 strcurve=rhino.getobject(“curve”)
 length=rhino.GetReal(“length”,7)
 offset=rhino.GetReal(“offset”,2)
 radius=rhino.GetReal(“radius”,10)
 factor=rhino.Getreal(“radius”,0.8)
 number=rhino.GetInteger(“number of division”,16)
 arrdivpt=rhino.DivideCurve(strcurve,number)
 Dim arrvector(),arrparam()
 For i=0 To number-3 Step 4
  ReDim Preserve arrvector(number)
  ReDim Preserve arrparam(number)
  arrparam(i)=rhino.CurveClosestPoint(strcurve,arrdivpt(i))
  arrvector(i)=rhino.curvecurvature(strcurve,arrparam(i))(1)
  arrparam(i+1)=rhino.CurveClosestPoint(strcurve,arrdivpt(i+1))
  arrvector(i+1)=rhino.curvecurvature(strcurve,arrparam(i+1))(1)
  arrparam(i+2)=rhino.CurveClosestPoint(strcurve,arrdivpt(i+2))
  arrvector(i+2)=rhino.curvecurvature(strcurve,arrparam(i+2))(1)
  arrparam(i+3)=rhino.CurveClosestPoint(strcurve,arrdivpt(i+3))
  arrvector(i+3)=rhino.curvecurvature(strcurve,arrparam(i+3))(1)
  Call createcircle(arrdivpt(i),arrvector(i),length,offset,rnd*radius+2,factor,0)
  Call createcircle(arrdivpt(i+1),arrvector(i+1),length,offset,rnd*radius+2,factor,30)
  Call createcircle(arrdivpt(i+2),arrvector(i+2),length,offset,rnd*radius+2,factor,60)
  Call createcircle(arrdivpt(i+3),arrvector(i+3),length,offset,rnd*radius+2,factor,90)
  
 Next
End Sub
 
Function createcircle(pt,vector,length,offset,radius,factor,angle)
 Dim plane,stem,center,circle
 center=rhino.PointAdd(pt,rhino.Vectorscale(rhino.VectorUnitize(vector),length))
 stem=rhino.AddLine(pt,center)
 plane=Rhino.planefromnormal(center,vector)
 circle=rhino.addcircle(plane,radius)
 Dim circle1,circle2,center1
 center1=rhino.PointAdd(center,rhino.Vectorscale(rhino.VectorUnitize(vector),offset))
 circle1=rhino.CopyObject(circle,center,center1)
 circle2=rhino.ScaleObject(circle,center,array(factor,factor,factor),True) 
 Call rhino.Rotateobjects(array(circle,circle1,circle2),center,angle,vector)
 Call leaf(pt,circle,circle1,circle2,stem)
End Function

Function leaf(pt,circle,circle1,circle2,stem)
 Dim divpt,divpt1,divpt2,midpt
 divpt=divide(circle,6)
 divpt1=divide(circle1,6)
 divpt2=divide(circle2,6)
 midpt=rhino.CurveMidPoint(stem)
 
 Dim i,a
 Dim curve10,curve11,curve12,curve20,curve21,curve22,loftsrf
 For i=0 To 4 Step 2
  a=i+2
  If a=6 Then
   a=0
  End If
  curve10=rhino.AddCurve(array(pt,midpt,divpt(i+1),divpt1(i+1)))
  curve11=rhino.AddCurve(array(pt,midpt,divpt(i),divpt1(i+1)))
  curve12=rhino.AddCurve(array(pt,midpt,divpt(a),divpt1(i+1))) 
  
  curve20=rhino.AddCurve(array(pt,midpt,divpt2(i+1),divpt1(i+1)))
  curve21=rhino.AddCurve(array(pt,midpt,divpt2(i),divpt1(i+1)))
  curve22=rhino.AddCurve(array(pt,midpt,divpt2(a),divpt1(i+1)))
  
  loftsrf=rhino.AddLoftSrf(array(curve11,curve21,curve20,curve22,curve12,curve10),,,,,,True)
  Call rhino.DeleteObjects(array(curve10,curve11,curve12,curve20,curve21,curve22))
 Next
 Call rhino.DeleteObjects(array(circle,circle1,circle2,stem))
End Function

Function divide(curve,number)
 divide=rhino.DivideCurve(curve,number)
End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s