• 登入
sketchucation logo sketchucation
  • 登入
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Compute Rotation and Scale from Transform Object

已排程 已置頂 已鎖定 已移動 Developers' Forum
26 貼文 9 Posters 4.6k 瀏覽
正在載入更多貼文
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • R 離線
    Ruts
    最後由 編輯 2015年9月17日 上午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 條回覆 最後回覆 回覆 引用 0
    • D 離線
      Dan Rathbun
      最後由 編輯 2015年9月17日 下午4:50

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

      I'm not here much anymore.

      1 條回覆 最後回覆 回覆 引用 0
      • R 離線
        Ruts
        最後由 編輯 2015年9月17日 下午6: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 條回覆 最後回覆 回覆 引用 0
        • D 離線
          Dan Rathbun
          最後由 編輯 2015年9月21日 下午8: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 條回覆 最後回覆 回覆 引用 0
          • J 離線
            Jernej Vidmar
            最後由 編輯 2016年6月4日 上午9: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 條回覆 最後回覆 回覆 引用 0
            • T 離線
              TIG Moderator
              最後由 編輯 2016年6月4日 下午1:22

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

              TIG

              1 條回覆 最後回覆 回覆 引用 0
              • 1
              • 2
              • 2 / 2
              • 第一個貼文
                最後的貼文
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement