sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Transformation Matrix Tool

    Scheduled Pinned Locked Moved Developers' Forum
    19 Posts 6 Posters 909 Views 6 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.
    • M Offline
      MartinRinehart
      last edited by

      I've been working on the chapter about the transformation matrix. I took the doc at face value when it said you have to understand the matrix (you don't) and figured it out (eventually). The result is this appendix that explains the thing:

      http://www.MartinRinehart.com/models/tutorial/tutorial_t.html

      I also got tired of looking at a list of 16 numbers, mentally reconstructing the matrix, so I wrote this little tool:

      
      # xform.rb - displays selected object's transformation matrix
      # Copyright 2009, Martin Rinehart
      
      require 'sketchup'
      
      
      def xform( html )
      
          model = Sketchup.active_model()
          sel = model.selection()
      
          thing = sel[0]
      
          if thing.is_a?( Sketchup;;ComponentInstance ) ||
                  thing.is_a?( Sketchup;;Group )
              trans = thing.transformation()
          else
              return
          end
          
          html += trans.to_a().inspect()
          html += "
              set_vals( vals );
          </script>
      
      </body>
      </html>"
          wd = UI;;WebDialog.new( "Transformation Matrix", true, 
      			'xform', 350, 200, 0, 0, true )
                  
          wd.set_html( html )
          
          wd.show()
      
      end # of xform()
      
      xform( "
      <html>
      <body>
      <table align=left bgcolor=#f0f0ff border=1 cellpadding=3>
          <tr>
              <td id=c0 align=right> </td>
              <td id=c1 align=right> </td>
              <td id=c2 align=right> </td>
              <td id=c3 align=right> </td>
          </tr>
          <tr>
              <td id=c4 align=right> </td>
              <td id=c5 align=right> </td>
              <td id=c6 align=right> </td>
              <td id=c7 align=right> </td>
          </tr>
          <tr>
              <td id=c8 align=right> </td>
              <td id=c9 align=right> </td>
              <td id=c10 align=right> </td>
              <td id=c11 align=right> </td>
          </tr>
          <tr>
              <td id=c12 align=right> </td>
              <td id=c13 align=right> </td>
              <td id=c14 align=right> </td>
              <td id=c15 align=right> </td>
          </tr>
          
      <script type='text/javascript'>
          function set_vals( vals ) {
          for ( var i = 0; i < 16; i++ ) {
              
              td = document.getElementById( 'c' + i );
              td.innerHTML = vals[i];
          }
      }
      vals =
      " )
      
      def xx()
          load __FILE__
      end
      
      # end of xform.rb
      
      

      Save this someplace convenient (not buried in Plugins). To use it, just load it. After loading once, it creates "xx" (rename if you like) that reloads it.

      xfrc.jpg

      Those created these:

      xf1.jpg

      xf2.jpg

      Happy New Year!

      xf3.jpg

      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

      1 Reply Last reply Reply Quote 0
      • R Offline
        remus
        last edited by

        Really sweet little tool martin, will help a lot with understanding those fiendish matrices, i think.

        http://remusrendering.wordpress.com/

        1 Reply Last reply Reply Quote 0
        • M Offline
          MartinRinehart
          last edited by

          @remus said:

          ... will help a lot with understanding those fiendish matrices, i think.

          Read the appendix. It's about two printed pages. You might change "fiendish" to "Oh! I get it." They're very clever, but well within range of anyone who passed high school math.

          Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

          1 Reply Last reply Reply Quote 0
          • honoluludesktopH Offline
            honoluludesktop
            last edited by

            Martin, Thanks. How about some graphic examples along with the math, you know for us visually oriented Architects:-), I had a professor that taught structural engineering calculus with graphics. No one did poorly in his class.

            1 Reply Last reply Reply Quote 0
            • M Offline
              MartinRinehart
              last edited by

              @honoluludesktop said:

              How about some graphic examples along with the math

              Didn't have time, Honolulu. Was out shoveling snow.

              Seriously, add graphics to the Appendix? I thought it was simple enough already. Wonder what others think.

              Others?

              Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

              1 Reply Last reply Reply Quote 0
              • honoluludesktopH Offline
                honoluludesktop
                last edited by

                Perhaps I'm mathematically impaired, but we can't argue with my professors success. His was the only class where everyone did well.

                In any case, I only meant to offer a constructive suggestion from someone at ground "0":-)

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

                  Hey Martin, this looks great. Each time I dig into Matrices I end up re-writing some code to format the matrix so I can read it in the ruby console. This will save much time I'm sure!

                  [Opinion]
                  The tutorial seems like a great start. I have to say that one of my big confusions is that it starts by talking about a 1x3 and a 3x3 matrix. While the information is true, it is confusing because SU uses the 4x4 matrix. I think it would be nice if it just jumped right into the 4x4 matrix. OR at least showed a series of 4x4 matrix examples at the end. Maybe it is good to start on the smaller 3x3 matrix to get the main ideas across. But please oh please show math examples with full 4x4 matrices. I still honestly do not understand them (well, I'm close to understanding them, but I was hoping your tutorial would show some more examples to help me see if I'm on the right track).[/Opion]

                  And lastly, you mention chapter 15 (which I think is not done yet?), but I wish you would turn the mention of the chapeter in a link. And also at the end you state:

                  The translation vector's origin point is unspecified. SketchUp's translation is always relative to the [0,0,0] origin.

                  I thinkt hat is wrong inside of Components definition where it uses the def's origin as 0,0,0 - I think. Maybe I should test that again first though.

                  Chris

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

                  1 Reply Last reply Reply Quote 0
                  • honoluludesktopH Offline
                    honoluludesktop
                    last edited by

                    Chris, that is what I have discovered when trying to manipulate the geometry inside a component. I could not figure out how a sub-component's axis (when unlike the model's) affect its transformation (if at all). Gave up and exploded the component to get at its parts. If you figure this out, please let me know:-) Btw, I haven't really had time to follow up on your last effort to help me. Perhaps this weekend.

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

                      @chris fullmer said:

                      I thinkt hat is wrong inside of Components definition where it uses the def's origin as 0,0,0 - I think. Maybe I should test that again first though.

                      Think that might depend. I think that when you open a group/component, SU transforms the co-ordinates to relate to SU origin instead of relative to definition origin.

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

                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        MartinRinehart
                        last edited by

                        @chris fullmer said:

                        I have to say that one of my big confusions is that [the tutorial appendix] starts by talking about a 1x3 and a 3x3 matrix. While the information is true, it is confusing because SU uses the 4x4 matrix.

                        What I knew, and should have said, is that there really isn't a 4x4 matrix. If this were first done in an OO world we'd have a transformation object that combined a 3x3 scale/rotate array and a 3d translation vector.

                        The new version includes this bit of table art in the intro:

                        xf3x3.jpg

                        Thanks for helping make this clear.

                        Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

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

                          I have seen Wt to be other than 1.0

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

                          1 Reply Last reply Reply Quote 0
                          • M Offline
                            MartinRinehart
                            last edited by

                            @chris fullmer said:

                            you state:

                            The translation vector's origin point is unspecified. SketchUp's translation is always relative to the [0,0,0] origin.

                            I think that is wrong inside of Components definition where it uses the def's origin as 0,0,0

                            I dunno. Try these two:

                            xfgroup.jpg

                            xfinst.jpg

                            I'm not positive about SU, but I am positive that the Transformation Matrix hack was worth the effort. At least we can talk about these things.

                            Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                            1 Reply Last reply Reply Quote 0
                            • M Offline
                              MartinRinehart
                              last edited by

                              @thomthom said:

                              I have seen Wt to be other than 1.0

                              I'd love to have an example!

                              Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

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

                                I don't remember exactly where I saw it. But I think Chris came across it recently while working on his Random Rotate and Scale plugin. I belive he'll be able to fill in the details here.

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

                                1 Reply Last reply Reply Quote 0
                                • TIGT Offline
                                  TIG Moderator
                                  last edited by

                                  This is the whole story ?TransformationMatrix.png

                                  TIG

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

                                    @martinrinehart said:

                                    I'd love to have an example!

                                    Take a component and use a uniform scaling method on it.

                                    t = Geom::Transformation.scaling 0.5 my_comp.transform! t

                                    They have applied uniform scaling by adjusting the 16th element. HOWEVER this caues problems with faceme components. Try it on one, and then orbit the model. The comonent gets all jumpy. This is a new bug in 7.1. The scaling method has worked the same way in previous version of SU, it is just how SU displays faceme's whose 16th element is not 1 has broke in 7.1. A bug has been filed and I'm begging them to get a fix out for 7.1 and not put it off until 8.0.

                                    I'll take a closer look at the new explanataion Martin. I think it looks hopeful that I might get this learned yet!

                                    Chris

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

                                    1 Reply Last reply Reply Quote 0
                                    • M Offline
                                      MartinRinehart
                                      last edited by

                                      According to Wikipedia, affine transformations never change Wt so it remains a 1. Perspective transformations do change it.

                                      I mention this in hopes that someone who understands will explain it to the rest of us.

                                      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                      1 Reply Last reply Reply Quote 0
                                      • honoluludesktopH Offline
                                        honoluludesktop
                                        last edited by

                                        Martin, My apologies;-) at third glance, it is illustrated, now that I know what I am looking at:-) Thanks.

                                        1 Reply Last reply Reply Quote 0
                                        • M Offline
                                          MartinRinehart
                                          last edited by

                                          @honoluludesktop said:

                                          Martin, My apologies;-)

                                          Apologies not needed. Besides, you're the only guy here who has the correct version number on Win XP.

                                          Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                          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