Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualDoublefris

Posted 07 April 2013 - 04:16 PM

EDIT: actually nvm it, something else about my code was faulty ^^


#2Doublefris

Posted 07 April 2013 - 03:46 PM

Say, if we were to implement quatornions, what would be the basic steps used to get an angular velocity? Find the angular displacement vector that is the lowest?

You would take the logarithm of the ratio of the target attitude and the current attitude. This is a quaternion whose real part is 0; the other three components give you the angular velocity that, when applied for 1 second, will convert the current attitude into the target attitude.
#include <iostream>
#include <boost/math/quaternion.hpp>

typedef boost::math::quaternion<double> Q;

int main() {
  Q a(0.0, 1.0, 0.0, 0.0);
  Q b(0.0, 0.0, 1.0, 0.0);

  Q ratio = b / a;
  double scale = std::acos(ratio.R_component_1());
  Q log_of_ratio(0.0,
                 scale * ratio.R_component_2(),
                 scale * ratio.R_component_3(),
                 scale * ratio.R_component_4());

  std::cout << log_of_ratio << '\n';
}


 

 

I've tried making this work in my XNA test ground, but can't quite get it to work.. 

What exactly does R_component do? Seems like it doesn't quite return the same results as the X,Y,Z,W functions in XNA.


#1Doublefris

Posted 07 April 2013 - 03:46 PM

Say, if we were to implement quatornions, what would be the basic steps used to get an angular velocity? Find the angular displacement vector that is the lowest?

You would take the logarithm of the ratio of the target attitude and the current attitude. This is a quaternion whose real part is 0; the other three components give you the angular velocity that, when applied for 1 second, will convert the current attitude into the target attitude.
#include <iostream>
#include <boost/math/quaternion.hpp>

typedef boost::math::quaternion<double> Q;

int main() {
  Q a(0.0, 1.0, 0.0, 0.0);
  Q b(0.0, 0.0, 1.0, 0.0);

  Q ratio = b / a;
  double scale = std::acos(ratio.R_component_1());
  Q log_of_ratio(0.0,
                 scale * ratio.R_component_2(),
                 scale * ratio.R_component_3(),
                 scale * ratio.R_component_4());

  std::cout << log_of_ratio << '\n';
}


I've tried making this work in my XNA test ground, but can't quite get it to work.. 

What exactly does R_component do? Seems like it doesn't quite return the same results as the X,Y,Z,W functions in XNA.


PARTNERS