Continuing the discussion from Ruby code and Automatic Sketchup:
Hi Tig,
I’ve gone back and revised the coding from “Automatic Sketchup”
First I rescaled the golden rectangles so as to have a radius of one, making the trigonometry easer.
I have created new code and have displayed all twenty triangles made into groups and then components.
What I want to do next is to have all twety triangles be the same component. I have worked and worked on this and am not sure how to proceed.
Is there a way to just go into the component info of each of the twenty triangles and make them the same identical component?
Or is there a way to take one component triangle and rotate it into all the other nineteen positions so as to have twenty identical triangles?
I have been studying my linear algebra and matrix mathematics and the Sketchup API but all the methods and translations and copies and transforms are confusing to get a grip on.
I know this could be a difficult problem or a simple one but I could use some more direction at this point.
Below I’ve added some of my code so you can see where I’m starting from.
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
t=Math.sqrt(5)+1
gr=t/2 #Golden rectangle
Cent_ang_rad=Math::atan2(1,gr) # converting the radius to one
y=Math::sin(Cent_ang_rad)
x=Math::cos(Cent_ang_rad)
r=Math::sqrt(y2+x2)
ssh=y #," ssh = Short side"
grh=x # Long side
#Golden rectangle face 1
grt1=
grt1[0] = [-grh,ssh,0] #P11
grt1[1] = [grh,ssh,0] #P12
grt1[2] = [grh,-ssh,0] #P13
grt1[3] = [-grh,-ssh,0] #P14
ent = mod.active_entities # Add the face to the entities in the model
group = ent.add_group # Add the group to the entities in the model
entities 1 = group.entities # Get the entities within the group
face1 = entities1.add_face grt1 # Add a face to within the group
#Golden rectangle face 2
grt2=
grt2[0] = [-ssh, 0,grh] #P21
grt2[1] = [ssh, 0, grh] #P22
grt2[2] = [ssh,0,-grh] #P23
grt2[3] = [-ssh, 0,-grh] #P24
ent = mod.active_entities # Add the face to the entities in the model
group = ent.add_group # Add the group to the entities in the model
entities = group.entities # Get the entities within the group
face2 = entities 2.add_face grt2 # Add a face to within the group
#Golden rectangle face 3
grt3=
grt3[0] = [0, -grh, ssh] #P31
grt3[1] = [0, grh, ssh] #P32
grt3[2] = [0, grh, -ssh] #P33
grt3[3] = [0, -grh, -ssh] #P34
ent = mod.active_entities # Add the face to the entities in the model
group = ent.add_group # Add the group to the entities in the model
entities = group.entities # Get the entities within the group
face3 = entities 3.add_face grt3 # Add a face to within the group
Now just two examples of triangles, all the rest are the same
Tryangl 1
pt21=Geom::Point3d.new(-ssh,0,grh) #pt2(1)
pt22=Geom::Point3d.new(ssh,0,grh) #pt2(2)
pt31=Geom::Point3d.new(0,-grh,ssh) #pt3(1)
#Tryangl 2
pt22=Geom::Point3d.new(-ssh,0,grh) #pt2(1)
pt31=Geom::Point3d.new(0,-grh,ssh) #pt3(1)
pt14=Geom::Point3d.new(-grh,-ssh,0) #pt1(4)
*************************************************************************************ent =Sketchup.active_model.entities
pm=Geom::PolygonMesh.new 12,20
#adding triangles to the sketch.
Tryangl 1
pm.add_polygon pt21,pt22,pt31
try1=
try1[0]=[-ssh,0,grh]
try1[1]=[ssh,0,grh]
try1[2]=[0,-grh,ssh]
ent=mod.active_entities # Add the face to the entities in the model
group=ent.add_group # Add the group to the entities in the model
entities 1=group.entities # Get the entities within the group
face1 = entities1.add_face try1 # Add a face to within the group
group.to_component
#Tryangl 2
pm.add_polygon pt21,pt31,pt14
try2=
try2[0]=[-ssh,0,grh]
try2[1]=[0,-grh,ssh]
try2[2]=[-grh,-ssh,0]
ent=mod.active_entities # Add the face to the entities in the model
group=ent.add_group # Add the group to the entities in the model
entities 2=group.entities # Get the entities within the group
face2= entities 2.add_face try2 # Add a face to within the group
group.to_component