• Login
sketchucation logo sketchucation
  • Login
Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

Compute Rotation and Scale from Transform Object

Scheduled Pinned Locked Moved Developers' Forum
26 Posts 9 Posters 4.9k Views 9 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.
  • R Offline
    Ruts
    last edited by 17 Sept 2015, 11:42

    I did delete the rotX/Y/Z methods, that's why I didn't understand where the variable xyz came from and why it could get value = 0/1/2. I do understand how methods with there variables work. Sorry was confused.

    On the other hand, I have been working with the euler_angle method for a while and now that I'm closely getting to a complete script I have noticed this method only partial works (for me?). Does it work for you guys? When I did draw shapes with a given rotation, the method didn't succeed to calculate the right angles for me so I did some research and made some changes. Here's the code I use:

    	def self.rotation(trans)
    		b = [trans.xaxis.to_a, trans.yaxis.to_a, trans.zaxis.to_a]
    		m = b.transpose.flatten!
    		if m[6] != 1 and m[6] != -1
    			ry = -Math.asin(m[6])
    			rx = Math.atan2(m[7]/Math.cos(ry),m[8]/Math.cos(ry))
    			rz = Math.atan2(m[3]/Math.cos(ry),m[0]/Math.cos(ry))
    		else
    			rz = 0
    			phipos = Math.atan2(m[1],m[2])
    			phineg = Math.atan2(-m[1],-m[2])
    			if m[6] == -1
    				ry = Math;;PI/2
    				rx = rz + phipos
    			else
    				ry = -Math;;PI/2
    				rx = -rz + phineg
    			end
    		end   
    	return [rx.radians,ry.radians,rz.radians]
    	end	
    

    First I found this document (page 5) that explains the calculations the way you do it. But it seems that you miss little pieces of code to make it complete.

    When I did calculate the angles it yet didn't calculate the right angles. So I did try some things and found out that the angles that were calculated represent the transpose matrix of the rotation that I need. So I fixed this by transposing the rotation matrix before the calculations.

    With these changes this piece of code does calculate the right angles. Did your code work for you?

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 17 Sept 2015, 16:50

      You realize that this topic thread is like 4 and 1/2 years old ?

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • R Offline
        Ruts
        last edited by 17 Sept 2015, 18:12

        @dan rathbun said:

        You realize that this topic thread is like 4 and 1/2 years old ?

        Yes, I have seen it. That does not mean that people can't come here and look for code that works? That's how I landed here. I was looking for some code that could convert the rotation matrix to euler angles. I found out that this code didn't work for me, so I did correct it and now I share it here just in case people experience the same problem as me. I'm just excited that I finally can contribute a little instead of always asking things!

        Nothing wrong with that, right?

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 21 Sept 2015, 20:05

          @ruts said:

          @dan rathbun said:

          You realize that this topic thread is like 4 and 1/2 years old ?

          Yes, I have seen it. ... Nothing wrong with that, right?

          I was referring to your asking questions of original posters, who might not remember, or might not even have been active here for some time.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jernej Vidmar
            last edited by 4 Jun 2016, 09:32

            Hello transformation gurus!

            just to double check the euler_angle(xyz=[]) method ... is the condition:

            if m[6] != 1 and m[6]!= 1
            

            at the beginning correct? Why double checking the same variable against the same value? Or is it meant to be:

            if m[6] != 1 and m[6]!= -1
            

            ?

            Cheers,
            Jernej

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 4 Jun 2016, 13:22

              An olde typo - use 1 for the second test...

              TIG

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

              Advertisement