• Login
sketchucation logo sketchucation
  • Login
⚠️ Attention | Having issues with Sketchucation Tools 5? Report Here

[Code] Print the transformation matrix

Scheduled Pinned Locked Moved Developers' Forum
14 Posts 5 Posters 2.1k Views 5 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
    Dan Rathbun
    last edited by 25 Jun 2012, 07:45

    Here's my simple brute force method:

      def trans_matrix_text( gt )
    
        return "Not a trnasformation object!" unless gt.is_a?(Geom;;Transformation)
        
        a = gt.to_a
        
        w = 3  # width
        a.each{|n| s = n.to_s.size; w = s if s>w }
        l = (w*4)+3
        
        # create a line output format string;
        fmt = "  | %#{w}s %#{w}s %#{w}s %#{w}s |\n"
        
        text = "\n"
        
        text << (32.chr*2)<<151.chr<<151.chr<<(32.chr*l)<<151.chr<<151.chr<<"\n"
        text << fmt % [  a[0].to_s,  a[1].to_s,   a[2].to_s,  a[3].to_s ]
        text << fmt % [  a[4].to_s,  a[5].to_s,   a[6].to_s,  a[7].to_s ]
        text << fmt % [  a[8].to_s,  a[9].to_s,  a[10].to_s, a[11].to_s ]
        text << fmt % [ a[12].to_s, a[13].to_s,  a[14].to_s, a[15].to_s ]
        text << (32.chr*2)<<151.chr<<151.chr<<(32.chr*l)<<151.chr<<151.chr<<"\n"
        
        return text
    
      end # def
    
      pt = Geom;;Point3d.new( 11,22,33 )
      text = trans_matrix_text( Geom;;Transformation.new(pt) )
      
      UI.messagebox( text, MB_MULTILINE, "Tranformation Matrix" )
    
    

    I have tweaked my system by copying Consolas font to the font used by dialogs, so I have monospaced text output. (It was easier than tweaking the resources in the executable after each update.)

    trans_matrix_MB.png

    trans_matrix_IO.png

    πŸ’­

    I'm not here much anymore.

    1 Reply Last reply Reply Quote 0
    • D Offline
      dacastror
      last edited by 26 Jun 2012, 03:00

      Thanks for responding, I have helped a lot. πŸ˜„

      me a question arises about the transformations. if I need to apply a transformation to an object but not in the principal coordinate axes, but the coordinate axes of a group (rotated) what should I use?

      (sorry for my bad English)

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 26 Jun 2012, 07:26

        You mean, transform an object around its own axis and not world axis?

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

        1 Reply Last reply Reply Quote 0
        • D Offline
          dacastror
          last edited by 27 Jun 2012, 16:47

          @thomthom said:

          You mean, transform an object around its own axis and not world axis?

          yes, exactly

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 27 Jun 2012, 19:02

            Create a local transformation and apply with with .transform!( tramsformation ) instead of setting the .transformation matrix manually. Or am I missing something?

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

            1 Reply Last reply Reply Quote 0
            • D Offline
              dacastror
              last edited by 28 Jun 2012, 18:15

              @thomthom said:

              Create a local transformation and apply with with .transform!( tramsformation ) instead of setting the .transformation matrix manually. Or am I missing something?

              How to create a local transformation? I would like to see some sample piece of code to guide me

              1 Reply Last reply Reply Quote 0
              • D Offline
                dacastror
                last edited by 28 Jun 2012, 18:37

                I wonder if there is any way to know the orientation of a group with respect to the axis of the world

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 28 Jun 2012, 18:44

                  You have the model's axes from X_AXIS etc and ORIGIN.
                  Then you have group.transformation.axes or group.transformation.xaxis etc... and group.transformation.origin too...
                  So you can find the relative locations [which are points3ds] and angles between axes [which are vector3ds] - see the methods for those types...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 28 Jun 2012, 19:16

                    @dacastror said:

                    @thomthom said:

                    Create a local transformation and apply with with .transform!( tramsformation ) instead of setting the .transformation matrix manually. Or am I missing something?

                    How to create a local transformation? I would like to see some sample piece of code to guide me

                    <span class="syntaxdefault"><br />point </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> instance</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transformation</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">origin<br />vector </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> instance</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transformation</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">yaxis<br />rotation </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"> point</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> vector</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 30</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">degrees </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">instance</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transform</span><span class="syntaxkeyword">!(</span><span class="syntaxdefault"> rotation </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span>
                    

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

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      dacastror
                      last edited by 28 Jun 2012, 20:11

                      thank you very much Thomas and Tig that prompt reply! πŸ˜„

                      I will try to implement your suggestions right now

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

                      Advertisement