sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Transformation.rotation multiple copy

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 229 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      crustybaps
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        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.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • C Offline
          crustybaps
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Yes, it'll be something like:

            <span class="syntaxdefault"><br /></span><span class="syntaxcomment">#&nbsp;Assuming&nbsp;mesh&nbsp;centred&nbsp;around&nbsp;origin.<br /></span><span class="syntaxdefault">tr&nbsp;</span><span class="syntaxkeyword">=&nbsp;</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">(&nbsp;</span><span class="syntaxdefault">ORIGIN</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">Z_AXIS</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">36.degrees&nbsp;</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">=&nbsp;</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">!&nbsp;{&nbsp;|</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">|&nbsp;</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">(&nbsp;</span><span class="syntaxdefault">tr&nbsp;</span><span class="syntaxkeyword">)&nbsp;}<br /></span><span class="syntaxdefault">new_face&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">holes&nbsp;</span><span class="syntaxkeyword">=&nbsp;[]<br />for&nbsp;</span><span class="syntaxdefault">loop&nbsp;in&nbsp;face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">loops<br />&nbsp;&nbsp;next&nbsp;</span><span class="syntaxkeyword">if&nbsp;</span><span class="syntaxdefault">loop</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">outer</span><span class="syntaxkeyword">?<br />&nbsp;&nbsp;</span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">=&nbsp;</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">!&nbsp;{&nbsp;|</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">|&nbsp;</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">(&nbsp;</span><span class="syntaxdefault">tr&nbsp;</span><span class="syntaxkeyword">)&nbsp;}<br />&nbsp;&nbsp;</span><span class="syntaxdefault">holes&nbsp;</span><span class="syntaxkeyword"><<&nbsp;</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">points&nbsp;</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">(&nbsp;</span><span class="syntaxdefault">holes&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;</span><span class="syntaxdefault"></span>
            

            Not tested!

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @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.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • C Offline
                crustybaps
                last edited by

                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 help

                for 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.degrees

                end

                1 Reply Last reply Reply Quote 0
                • jolranJ Offline
                  jolran
                  last edited by

                  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 = nil

                  So 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.

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    crustybaps
                    last edited by

                    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.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement