sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Rotating into XY plane

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 1.3k Views 3 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.
    • D Offline
      duncan
      last edited by

      Hi all!
      Is there some code around that will take any face and rotate it into the xy plane?

      1 Reply Last reply Reply Quote 0
      • fredo6F Offline
        fredo6
        last edited by

        Duncan,

        The best is to use the Transformation class.
        You need of course to indicate an origin point and an angle
        The code below will work on a single face or a list of faces

        
        def face_rotation_XY(list_faces, origin, angle)
           t = Geom;;Transformation.rotation origin, Z_AXIS, angle  
           Sketchup.active_model.active_entities.transform_entities t, list_faces
        end
        
        

        Fredo

        1 Reply Last reply Reply Quote 0
        • D Offline
          duncan
          last edited by

          Thanks Fredo,

          I am thinking my question could have been phrased more clearly. I was looking for some code that will take an arbitrarily placed face (perhaps with no edges lying in the xy, xz, or yz planes) and transform it into the XY plane.

          The transformation would be a combination of two rotations.

          1 Reply Last reply Reply Quote 0
          • D Offline
            duncan
            last edited by

            Thank you Fredo. I did in fact wish a privileged direction. Worked like a charm.

            1 Reply Last reply Reply Quote 0
            • T Offline
              tomot
              last edited by

              Nice example Fredo6:

              Its too bad we don't have a permanent place to store these types of examples. Someone at SU should be collating this stuff, if not, at least to improve the totally sad state of affairs, where only words are used to describe how the Ruby API is to be implemented in SU.

              Most programming languages use the same old irrelevant tired examples on how to learn programming.
              Example: how to code "hello my name is?

              Here we have a 3d program, with a Ruby API, and the best description to date is to describe
              the API in words, most of which don't even use synonyms in the description.

              "A picture is worth a thousand words" ....... Hello out there SU technical staff!
              Lets get a bit more creative, like the 1000's that use this program.

              [my plugins](http://thingsvirtual.blogspot.ca/)
              tomot

              1 Reply Last reply Reply Quote 0
              • fredo6F Offline
                fredo6
                last edited by

                Then, you can use a reverse Axis transformation.

                Transform xy plane 2.jpg
                The following code would for instance transform any given face to be in the XY plane, with its barycentre at the Origin.

                
                	axes = face.normal.axes
                	origin = face.bounds.center
                	t = Geom;;Transformation.axes(origin, axes[0], axes[1], axes[2]).inverse
                
                	Sktechup.active_model.entities.transform_entities t, face
                
                

                The drawback of the above method is that the orientation of the transformed face in the XY plane is not predetermined.

                So, if you wish to have a privileged direction, for instance an edge of the face to define the X axis, then use the following code instead, which will ensure that the selected <edge> defines the X axis, and that the Origin corresponds to the Start vertex of the edge.

                
                	origin = edge.start.position
                	xvec = origin.vector_to edge.end.position
                	zvec = face.normal
                	yvec = zvec * xvec
                	
                	t = Geom;;Transformation.axes(origin, xvec, yvec, zvec).inverse
                
                

                Transform xy plane.jpg
                Note that you can use the transformation <t> to calculate the coordinates of points to reconstruct a copy of the face, instead of transform it.

                
                	entities = Sketchup.active_model.entities
                	face.loops.each do |loop|
                		f = entities.add_face loop.vertices.collect { |v| t * v.position }
                		entities.erase_entities f unless loop.outer?    # for holes
                	end	
                
                

                Hope this help!

                Fredo

                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