   Gimble Lock - Possible Workarounds?
  Hi guys,I haven't tested the following out myself yet I just wanted to post two possible Gimble Lock workarounds to find out if any of you guys already know if they work.Can Gimble Lock be avoid by...1 ) Limiting matrix rotation to one or two axis?2 ) Making sure no angles are used that are multiples of 90 (degress)?I am using Euler angles, and yes I am aware of Quaternions but I'm looking for a way to avoid Gimble Lock when using Euler angles. :)   
  No, mathematically it is not possible to avoid it without adding additional information to the system.There are orientations where 2 of the 3 rotations will lie on the same plane, and when that happens it is locked. You can introduce a fourth gimbal (rotation axis) and constrain the set to avoid a lock along three axis.  Or you can use a translation matrix.  Or you can use quaternions.  Or you can choose an alternative (more complex) representation.  Each solution presents their own set of difficulties and benefits.   ;  If you made sure the angles relative to each other were not multiples of 90 degrees, that seems like it would work. I'm not very familiar with this area exactly, but I do remember the simple identity of sine(pi/2 + angle) = cosine(angle) or in other words, they are the same function shifted 90 degrees. Assuming you are using a standard base.. if you have some skewed coordinate system where the planes do not intersect at 90 degree angles, you have to take that into account.Also, if you are only doing rotations on one axis, there is no gimble lock clearly. However, it might be possible that the two axes you rotate happen to be the two locked together if you are not taking that into account.. I might have misunderstood what you meant by limiting the matrix rotations to one or two axes?   ;Quote:I am using Euler angles, and yes I am aware of Quaternions but I'm looking for a way to avoid Gimble Lock when using Euler angles. :)First of all, quaternions have no special properties with respect to gimbal lock, so although it wouldn't hurt anything to use them, there's certainly no need to do so.Gimbal lock will always be a possibility when building an orientation from scratch using Euler angles, but given certain constraints you may be able to avoid it. Also, gimbal lock isn't always undesirable, so it's not a given that you even *need* to avoid it.The questions that comes to mind are:1. What type of motion are you trying to achieve?2. Why have you chosen Euler angles as your rotation representation?   ;  Thanks for the quick replies. :)@moffIf ensuring the difference between two angles is not 90 degrees can actually be used to avoid Gimbal Lock then that sounds like it would be an ideal solution for me. It has just gone 3:00am here so I'm not going to start any serious coding right now but the first thing that sprang to mind was this...// pseudo code// using degrees instead of radians for readabilityx = -45 // rotation around the x axisy = 135 // rotation around the y axisif( x < 0 ) x += 360if( y < 0 ) y += 360d = x - y;if( d % 90 == 0 ) // difference between angles is 90 ( gimbal lock alert! )So, if the difference between the first two angles is 90 then I guess one of those angles needs to be offset by a very small amount. This might be an issue for some people in certain situations but I could live with a small degree (no pun intended) of precision loss if it means Gimbal Lock will be avoided.Do you guys think this is worth following up?@jykIt is a personal thing really, I'm comfortable using and working with Euler angles and I haven't really had a need to move over to Quaternions yet. No doubt I will one day though.   ;Quote:It is a personal thing really, I'm comfortable using and working with Euler angles and I haven't really had a need to move over to Quaternions yet. No doubt I will one day though.Just wanted to clarify a couple of things. What I was trying to say earlier is that there's no need to switch to quaternions. Switching to quaternions will not help you avoid gimbal lock; conversely, it's perfectly possible to avoid gimbal lock without using quaternions.As for gimbal lock itself, if you *really* want to avoid it entirely, your best bet would be not to use Euler angles.   ;  Most applications of Euler angles do not experience gimbal lock. If you aren't doing IK and you aren't using spherical angles you are most likely fine. In particular, if you are setting individual euler angles directly and not trying to accomplish particular goal orientations (such as is the case with the standard FPS camera) it is impossible to experience gimbal lock.   ;Quote:Original post by jykJust wanted to clarify a couple of things. What I was trying to say earlier is that there's no need to switch to quaternions. Switching to quaternions will not help you avoid gimbal lock; conversely, it's perfectly possible to avoid gimbal lock without using quaternions.In that case I doubt I will be switching to quaternions any time soon. :)Quote:Original post by jykAs for gimbal lock itself, if you *really* want to avoid it entirely, your best bet would be not to use Euler angles.That is assuming this theoretical "catch 'n' kill 90 degree angles" solution doesn't work. If it does work it will certainly put a smile on a lot of peoples faces that is for sure.   ;Quote:Original post by SneftelMost applications of Euler angles do not experience gimbal lock. If you aren't doing IK and you aren't using spherical angles you are most likely fine. In particular, if you are setting individual euler angles directly and not trying to accomplish particular goal orientations (such as is the case with the standard FPS camera) it is impossible to experience gimbal lock.I guess it would help if I explained the kind of applications I develop, there is no IK going on (yet) but FPS cameras are definitely something I play around with now and again.I didn't create this site but it is a perfect example of the kind of stuff I am developing: http://www.ecodazoo.com   ;  Let me know how it turns out if you decide to test it out. Have you already tried any code that produced noticeable gimbal lock to compare against? That would be pretty interesting to be able to see the differences.   