Skip to main content
added 3 characters in body
Source Link
hatch22
  • 166
  • 1
  • 4

So losing precision is generally unavoidable if youyou're using limited precision numbers like float or double. However, there is still hope. One strategy to help prevent the repeated inversions getting worse and worse is to re-normalize the quaternion after each inversion (or after a few of them if you can tolerate more error).

So losing precision is generally unavoidable if you using limited precision numbers like float or double. However, there is still hope. One strategy to help prevent the repeated inversions getting worse and worse is to re-normalize the quaternion after each inversion (or after a few of them if you can tolerate more error).

So losing precision is generally unavoidable if you're using limited precision numbers like float or double. However, there is still hope. One strategy to help prevent the repeated inversions getting worse and worse is to re-normalize the quaternion after each inversion (or after a few of them if you can tolerate more error).

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

This keeps the precision loss from growing out of control. See also this StackOverflow questionthis StackOverflow question.

This keeps the precision loss from growing out of control. See also this StackOverflow question.

This keeps the precision loss from growing out of control. See also this StackOverflow question.

Edited Normalize function to use an extension method since the OP is using Unity with C#
Source Link
hatch22
  • 166
  • 1
  • 4
public static class QuaternionExtensions { public static Quaternion Normalize(this Quaternion q)  {   Quaternion result;   float sq = q.x * q.x;   sq += q.y * q.y;   sq += q.z * q.z;   sq += q.w * q.w;   //detect badness   assert(sq > 0.1f);   float inv = 1.0f / sqrt(sq);   result.x = q.x * inv;   result.y = q.y * inv;   result.z = q.z * inv;   result.w = q.w * inv;   return result; } } 
Quaternion Normalize(Quaternion q) { Quaternion result; float sq = q.x * q.x; sq += q.y * q.y; sq += q.z * q.z; sq += q.w * q.w; //detect badness assert(sq > 0.1f); float inv = 1.0f / sqrt(sq); result.x = q.x * inv; result.y = q.y * inv; result.z = q.z * inv; result.w = q.w * inv; return result; } 
public static class QuaternionExtensions { public static Quaternion Normalize(this Quaternion q)  {   Quaternion result;   float sq = q.x * q.x;   sq += q.y * q.y;   sq += q.z * q.z;   sq += q.w * q.w;   //detect badness   assert(sq > 0.1f);   float inv = 1.0f / sqrt(sq);   result.x = q.x * inv;   result.y = q.y * inv;   result.z = q.z * inv;   result.w = q.w * inv;   return result; } } 
Source Link
hatch22
  • 166
  • 1
  • 4
Loading