Transformation.rotation multiple copy
-
I am wanting to know how may I use the code in a loop to create multiple copies of face.
t=Geom::Transformation.rotation [0,0,0],[0,1,0], theta
ents.transform_entities t, face -
You need to collect all the 3d points of the face and then transform there - then use
entities.add_face
.However, not that once you have faces with holes that won't work correctly and you have to first take the outer loop, create a face for these vertices -then take all the inner loop and create faces for these which you erase - creating holes in the new face.
-
Does this mean that I put the 3d points into an array and then perform the transformation on the array?
There are no holes in the face yet I will try that excercise next but for now I will try to get the angle correct. My angle in radians is 36 degrees and I am trying to create a gear wheel with ten teeth. The code below works to a certain degree but I am getting 5 copies only instead of the nine I was expecting. Its an improvement on my previous attempts.
for i in 1..10
#create the transformation object
t=Geom::Transformation.rotation [0,0,0],[0,1,0], theta
#transform the face
ents.transform_entities t, face
#add the face back to its original position for another transformation
face=ents.add_face pts
#increase the angle of rotation by another 36 degrees
theta=theta+theta
end -
Yes, it'll be something like:
<span class="syntaxdefault"><br /></span><span class="syntaxcomment"># Assuming mesh centred around origin.<br /></span><span class="syntaxdefault">tr </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">rotation</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">ORIGIN</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">Z_AXIS</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">36.degrees </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">outer_loop</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">map</span><span class="syntaxkeyword">! { |</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">| </span><span class="syntaxdefault">v</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transform</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">tr </span><span class="syntaxkeyword">) }<br /></span><span class="syntaxdefault">new_face </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">holes </span><span class="syntaxkeyword">= []<br />for </span><span class="syntaxdefault">loop in face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">loops<br /> next </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">loop</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">outer</span><span class="syntaxkeyword">?<br /> </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">loop</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">map</span><span class="syntaxkeyword">! { |</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">| </span><span class="syntaxdefault">v</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transform</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">tr </span><span class="syntaxkeyword">) }<br /> </span><span class="syntaxdefault">holes </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end<br />entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase_entities</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">holes </span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault"></span>
Not tested!
-
@crustybaps said:
... I am trying to create a gear wheel with ten teeth. ...
It would be MUCH simpler to draw the axial profile, then pushpull the face to the gear's thickness.
I made a plugin that draws a Hypocycloid Cam profile (a translation from a python script.)
My next phase is to prompt the user for a thickness and do the pushpulling.
It's in the Extension Warehouse.. if you wish to take a look at the code.
-
Thanks I'll take a look.
What I have so far is below which seems to have done the job. Theres still a lot of dots to fill in yet as far as connecting the teeth and forming the correct profile for the teeth, but this is a good start. Thanks for all the helpfor i in 1..n_teeth
#create the transformation object
t=Geom::Transformation.rotation [0,0,0],[0,1,0], theta
points = face.outer_loop.vertices.map! { |v| v.position.transform( t ) }
new_face = ents.add_face( points )
new_face.material='green'
new_face.pushpull 2
ents.add_face pts
theta=theta+angle.degreesend
-
Correct me if I'm wrong. Isent it so that when using pushpull the return is nil?
So one cannot do face2 = face1.pushpull(100, true)
face2 = nilSo if you wish to do something to the pushpulled faces. Inside a group or component you have to recollect old and pushpulled faces in 2 arrays and subtract from the original faces to retrieve the new pushpulled ones.
Unless someone figured out some workaround around this problema.
As Dan mentioned it is most likely the simplest method even if recolletion has to be done.
You might not be doing something to the newly created faces, just mentioning it here since it tripped me up before doing something similar. -
Yes I think it is a simpler way to draw the profile and pushpull, but once I started along the path of rotation I was getting some unusual things happening and I wanted to know what was going on.
I'm on a learning curve with transformations so I will be looking into all the points highlighted here.
I want to be able to define the number of teeth on each wheel and the diameter of the wheel. There will be eight wheels in all- I am modelling the back sprocket of a bicycle wheel and would like the script to ask how many wheels on the sprocket? What are their diameters? and what is the separation between each wheel.
If I were to go along the route suggested by Dan I would have eight separate pushpulls of the axial profiles but this still would probably less error prone and much simpler.
Advertisement