• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

[Code] Transforming in custom coordinate systems

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 152 Views 2 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.
  • T Offline
    thomthom
    last edited by 5 Oct 2012, 21:04

    Here's a snippet that I had to bend my mind to understand. I wanted to scale entities along the axis of the currently open group or component using one transformation on the entities.

    Entities in SketchUp are transformed in global coordinates so I had to transform my local scaling transformation into one that worked in the global space.

    I couldn't get it working for a long time, until I re-read this Wikipeadia article:
    http://en.wikipedia.org/wiki/Transformation_matrix#Composing_and_inverting_transformations

    @unknownuser said:

    (This is called the Associative property.) In other words, the matrix of the combined transformation A followed by B is simply the product of the individual matrices. Note that the multiplication is done in the opposite order from the English sentence: the matrix of "A followed by B" is BA, not AB.

    <span class="syntaxdefault"><br /></span><span class="syntaxcomment"># This will scale selected face 2x in the X direction<br /># of the currently open group / component<br /></span><span class="syntaxdefault">face </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">local_coords </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">edit_transform<br />local_scale  </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">scaling</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> 2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1 </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transform_entities</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> local_coords </span><span class="syntaxkeyword">*</span><span class="syntaxdefault"> local_scale </span><span class="syntaxkeyword">*</span><span class="syntaxdefault"> local_coords</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">inverse</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> face </span><span class="syntaxkeyword">)<br />&nbsp;</span><span class="syntaxdefault"></span>
    

    Just a moment...

    favicon

    (stackoverflow.com)

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

    1 Reply Last reply Reply Quote 0
    • R Offline
      renderiza
      last edited by 6 Oct 2012, 09:08

      Hi,

      This solves a big problem since at least for me, maintaining the local axis of the object I want to scale is important. Thanks for this great share!

      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 6 Oct 2012, 10:01

        😄 Glad it helped.

        I spend a loong time on that - I just couldn't warp my head around what was going on. The key was the quote from the Wiki article. Everything makes so much more sense now.

        Figured I'd post it here to remind myself.

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

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

        Advertisement