Notifications
Clear all

[Closed] Preventing Sign Flips from rotation conversions?

Hi all, I have a question regarding rotation conversions, I’ve tried to fix rotation sign flips when converting from quaternion onto euler, and here what’ve I come so far:


  for i = animationrange.start.frame to animationrange.end.frame do
  (
  	at time i NewEul = ($.rotation as eulerAngles).z --Original Z rotation Value
  	turn = 0 -- Original turn value
  	if NewEul >= (-180) and NewEul < 0 do  -- check if Z_rot values is greater than -180 and smaller than 0 (sign flip prevention)
  		(
  			at time i NewEul = ($.rotation as eulerAngles).z + 360 -- correct Z rotation values
  		)
  	if NewEul == 360 do -- check if Z rotation values already achieved 360 degrees
  		turn +=1 -- increment turn value to store multiple revolutions
  	at time i FinEul = NewEul + (turn * 360)  -- generate final Values base on corrected value and number of turns
  	format "frame: % Z_eulerValue: % Turns:% 
" i FinEul turn   -- print Values
  )
  

But somehow the turn value won’t increment when the corrected value achieve 360 degrees, maybe someone can help me with this? (I’m pretty noob with scripts)

Thanks.

PS:to reproduce this, simply create object and animate the rotation it in z axis for 720 degrees.