Grasshopper

algorithmic modeling for Rhino

Hi guys,

Would anyone know how to create a fractal based Truss system like the image attached using python? I am a beginner in python.

I found someone who has done it in grasshopper python but I have no clue how it works https://iasefmdrian.wordpress.com/2014/08/16/fractruss-an-applicati...

Any help would be greatly appreciated :)

Views: 935

Attachments:

Replies to This Discussion

I got to this far. I could not figure out how to finish the def below, would anyone please take a look snd see if you can help me:

def recursive(v1, v2, v3, iteration, lineList):

if(iteration>0):

newPts = FractalTriangle(v1, v2, v3)
line = rs.AddPolyline([newPts[0], newPts[1], newPts[2]...?
lineList.append(line)

recursive(newPts[4], newPts[0], newPts[1], (iteration-...?
recursive(newPts[3], newPts[4], newPts[2], (iteration-...?
recursive(newPts[1], newPts[2], newPts[6], (iteration-...?

Below here is the entire code so far:

import rhinoscriptsyntax as rs
from math import *

#---Initial seeds----------

angle = rs.Angle(v1, v3)
angle = angle[0]
print angle

def FractalTriangle(v1, v2, v3):

L1 = rs.Distance(v1, v2)
L2 = rs.Distance(v1, v3)
L3 = rs.Distance(v2, v3)

l1 = (L2**2)/L1 #triangle(v1v2v3):triangle(v1,v3,p1),so,L...
l2 = (L3**2)/L1 #triangle(v1v2v3):triangle(v2,v3,p2),so,L...
l3 = L1 - 11 - 12 #because,l1+l2+l3=L1
l4 = l3*(L2/L1) ##triangle(v1v2v3):triangle(p1,p2,p3),so...

#---------Frist Point----------
p1 = v2 - v1
p1 = rs.VectorUnitize(p1)
p1 = p1*11
p1 = v1 + p1

#----------Last Point----------
p2 = v2 - v1
cross = v2 - v1
cross = rs.VectorUnitize(cross)
cross = rs.VectorRotate(cross, angle, [0,0,1])
cross = cross*14
p3 = rs.VectorUnitize(p3)
p3 = p3*11 # means, p2 = p2 * dist/2
p3 = v1+p3+cross

return (v1, p1, p2, v2, v3, p2, p3, p1, v3, p3, v3, v1)

def recursive(v1, v2, v3, iteration, lineList):

if(iteration>0):

newPts = FractalTriangle(v1, v2, v3)
line = rs.AddPolyline([newPts[0], newPts[1], newPts[2]...
lineList.append(line)

recursive(newPts[4], newPts[0], newPts[1], (iteration-...
recursive(newPts[3], newPts[4], newPts[2], (iteration-...
recursive(newPts[1], newPts[2], newPts[6], (iteration-...

return lineList

#----------returning the call----------

allLines = []
a = recursive (v1, v2, v3, iteration, allLines)

angle1 = rs.Angle(v1, v3)
angle2 = rs.Angle(v2, v3)

theta1 = angle1[0]
theta2 = 180.0 - angle2[0]

Hi,

I think it's something like this, but there is an issue after the 2nd iteration:

import rhinoscriptsyntax as rs
from math import *

angle = rs.Angle(v1, v3)
angle = angle[0]
print angle

def FractalTriangle(v1, v2, v3):
L1 = rs.Distance(v1, v2)
L2 = rs.Distance(v1, v3)
L3 = rs.Distance(v2, v3)

l1 = (L2**2)/L1 #triangle(v1,v3,p1)
l2 = (L3**2)/L1 #triangle(v1,v3,p1)
l3 = L1 - l1 - l2
l4 = l3 * (L2 / L1)


#first point
p1 = v2 - v1
p1 = rs.VectorUnitize(p1)
p1 = p1 * l1
p1 = v1 + p1


#last point
p2 = v2 - v1
p2 = rs.VectorUnitize(p2)
p2 = p2 * (l1 + l3)
p2 = v1 + p2


#mid point
p3 = v2 - v1
cross = v2 - v1
cross = rs.VectorUnitize(cross)
cross = rs.VectorRotate(cross, angle, [0,0,1])
cross = cross*l4
p3 = rs.VectorUnitize(p3)
p3 = p3*l1 #means p2 =p2 *dist/2
p3 = v1+p3+cross


return (v1, p1, p2, v2, v3, p2, p3, p1, v3, p3, v3, v1)

def recursive(v1, v2, v3, iteration, lineList):
if(iteration>0):
newPts = FractalTriangle(v1, v2, v3)
line = rs.AddPolyline(newPts)
lineList.append(line)

recursive(newPts[4], newPts[0], newPts[1], iteration - 1, lineList)
recursive(newPts[3], newPts[4], newPts[2], iteration - 1, lineList)
recursive(newPts[1], newPts[2], newPts[6], iteration - 1, lineList)

return lineList #returning the call

allLines = []
a = recursive(v1, v2, v3, iteration, allLines)

angle1 = rs.Angle(v1, v3)
angle2 = rs.Angle(v2, v3)

theta1 = angle1[0]
theta2 = 180.0 - angle2[0]

Good news: 6 fractal "modes" (any "new" mode is very easy to add) plus a zillion options

Bad news: it's C# (and rather impossible to translate to P "automatically").

BTW: The Ryan mode is some specific "points set-up" for my friend Ryan (you can by-pass it).

best

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service