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

    Transformation array

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 4 Posters 1.5k 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.
    • chrisglasierC Offline
      chrisglasier
      last edited by

      Please could someone tell me where to find out what these numbers represent in this array.transform.gif

      Thanks

      Chris

      With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        Hi,
        This is the 4x4 matrix of the transformation of either a group or a component.

        Try this snippet (assuming you've got 'trans' from a group/component):

        trans=trans.to_a
        
            scalex=Math.sqrt(trans[0]**2+trans[1]**2+trans[2]**2)
            scaley=Math.sqrt(trans[4]**2+trans[5]**2+trans[6]**2)
            scalez=Math.sqrt(trans[8]**2+trans[9]**2+trans[10]**2)
                     
            scale=scalex
            scale=scaley if scaley>scale
            scale=scalez if scalez>scale
        
            puts "         <pos>#{trans[12]} #{trans[13]} #{trans[14]}</pos>\n"
            puts "         <scale>#{scale}</scale>\n"   
            puts "         <rotation>\n"
            puts "            <matrix>\n"
            puts "               #{trans[0]/scalex} #{trans[4]/scaley} #{trans[8]/scalez} #{trans[1]/scalex} #{trans[5]/scaley} #{trans[9]/scalez} #{trans[2]/scalex} #{trans[6]/scaley} #{trans[10]/scalez}\n"
            puts "            </matrix>\n"
            puts "         </rotation>\n"
        

        Hope this helps,

        DB

        1 Reply Last reply Reply Quote 0
        • chrisglasierC Offline
          chrisglasier
          last edited by

          Thanks, Didier, but it seems I fell at the second hurdle.

          transform3.gif

          I am afraid I'm a bit out of my depth here. I just want to be able to click on a group or component and have it send its index, xyz and rotation to a javascript array. The index part I can do, so I would be very grateful for any further help with the rest.

          My regards

          Chris

          With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            The array represents the Transformation Matrix of the entity. Normally, you don't need to access it in the array form because the Trasformation class has methods for access:

            
            # position; a single point (Point3d)
            selection.transformation.origin
            
            # You need 3 vectors to describe the objects rotation in 3d space
            selection.transformation.xaxis
            selection.transformation.yaxis
            selection.transformation.zaxis
            
            

            Hi

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by

              Chris,

              I just realized you probably want the rotation values in a more friendly form for your namesets project. The set of 3 vectors wouldn't be easy to enter, nor understand for that purpose. What does your human interface look like for editing the rotation of an object?

              Hi

              1 Reply Last reply Reply Quote 0
              • chrisglasierC Offline
                chrisglasier
                last edited by

                @jim said:

                What does your human interface look like for editing the rotation of an object?

                Thanks, Jim. Yes the idea is to make namesets and Sketchup work together both ways.

                xyz DEC 7.gif
                Rotation FEB 7.gif
                (Edit: I should also say that components move on confirm)

                The input boxes for xyz's and rotation are populated at start up from a csv record (turned into an array) and can be edited and values returned to the array. The call backs in the ruby look like this:

                
                theX = Integer(a[1]).mm
                theY= Integer(a[2]).mm
                theZ = Integer(a[3]).mm
                    
                point = Geom;;Point3d.new theX,theY,theZ
                txyz = Geom;;Transformation.new point
                
                #Courtesy of Jim Foltz
                
                theDegrees = Integer(a[4]).degrees
                theAxis = a[5]
                	
                rv = Geom;;Vector3d.new(0,0,1) if theAxis == "z"
                rv = Geom;;Vector3d.new(0,1,0) if theAxis == "y"
                rv = Geom;;Vector3d.new(1,0,0) if theAxis == "x"
                	
                tr = Geom;;Transformation.rotation(Geom;;Point3d.new(instance.bounds.center), rv, theDegrees)
                	
                instance.transform! tr 
                
                
                

                What would be good would be for the same editing to be done with the move and protractor tools. It seems this is a bit like the relationship between tools and the VCB (now sensibly Measurements).

                So, for example, I am now working on animating the distribution of sanitaryware on a building site. In order to set the distribution paths it would be intuitive to click on the destination floor component (rather than a name on a list) and then adjust the route. But then I need the XYZ and rotation to be sent to the js array. The rotation may also be important to turn components to pass through door openings or stack in a material hoist, but maybe not. XYZ's are essential.

                Any further help most gratefully received!

                My regards

                Chris

                With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                1 Reply Last reply Reply Quote 0
                • chrisglasierC Offline
                  chrisglasier
                  last edited by

                  @didier bur said:

                  Hi,
                  This is the 4x4 matrix of the transformation of either a group or a component.

                  Try this snippet (assuming you've got 'trans' from a group/component):

                  trans=trans.to_a
                  > 
                  >     scalex=Math.sqrt(trans[0]**2+trans[1]**2+trans[2]**2)
                  >     scaley=Math.sqrt(trans[4]**2+trans[5]**2+trans[6]**2)
                  >     scalez=Math.sqrt(trans[8]**2+trans[9]**2+trans[10]**2)
                  >              
                  >     scale=scalex
                  >     scale=scaley if scaley>scale
                  >     scale=scalez if scalez>scale
                  > 
                  >     puts "         <pos>#{trans[12]} #{trans[13]} #{trans[14]}</pos>\n"
                  >     puts "         <scale>#{scale}</scale>\n"   
                  >     puts "         <rotation>\n"
                  >     puts "            <matrix>\n"
                  >     puts "               #{trans[0]/scalex} #{trans[4]/scaley} #{trans[8]/scalez} #{trans[1]/scalex} #{trans[5]/scaley} #{trans[9]/scalez} #{trans[2]/scalex} #{trans[6]/scaley} #{trans[10]/scalez}\n"
                  >     puts "            </matrix>\n"
                  >     puts "         </rotation>\n"
                  

                  Hope this helps,

                  Yes thanks Didier. It just took me a long time to start to get to grips with it. Now here is a situation that has thrown me.

                  Bounding box removed

                  The component sits nicely at 0, 0 on X and Y as trans[12] and trans[13] but at -100 mm not as trans[14] on Z. Is it something to do with the axes settings perhaps?

                  Thanks

                  Chris

                  With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                  1 Reply Last reply Reply Quote 0
                  • Chris FullmerC Offline
                    Chris Fullmer
                    last edited by

                    That transformation origin is the components axis. So it looks like perhaps the axis on the component is not set at the base of the component.

                    Is that the case?

                    Chris

                    Lately you've been tan, suspicious for the winter.
                    All my Plugins I've written

                    1 Reply Last reply Reply Quote 0
                    • chrisglasierC Offline
                      chrisglasier
                      last edited by

                      @chris fullmer said:

                      Is that the case?

                      Yes! I don't know why it happened, but now I know a little bit more - e.g. to refer to the comp axis when editing. Thanks

                      Chris

                      With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                      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