quaternion2yaw.cpp
Go to the documentation of this file.
00001 
00007 /*****************************************************************************
00008 ** Includes
00009 *****************************************************************************/
00010 
00011 #include <iostream>
00012 #include <ecl/command_line.hpp>
00013 #include <ecl/linear_algebra.hpp>
00014 #include <ecl/math.hpp>
00015 
00016 /*****************************************************************************
00017  * Using
00018  ****************************************************************************/
00019 
00020 using ecl::ArgException;
00021 using ecl::CmdLine;
00022 using ecl::UnlabeledValueArg;
00023 
00024 /*****************************************************************************
00025 ** Main program
00026 *****************************************************************************/
00027 int main(int argc, char** argv) {
00028 
00029     /******************************************
00030      * Parse for the port name
00031      ******************************************/
00032     bool hex(false);
00033     double x, y, z, w;
00034 
00035     try {
00036         CmdLine cmd("Calculator for yaw to quaternion.",' ',"0.1");
00037         UnlabeledValueArg<double> arg_x("x","Quaternion component - x",true,0.0,"float", cmd);
00038         UnlabeledValueArg<double> arg_y("y","Quaternion component - y",true,0.0,"float", cmd);
00039         UnlabeledValueArg<double> arg_z("z","Quaternion component - z",true,0.0,"float", cmd);
00040         UnlabeledValueArg<double> arg_w("w","Quaternion component - w",true,0.0,"float", cmd);
00041         cmd.parse(argc,argv);
00042         x = arg_x.getValue();
00043         y = arg_y.getValue();
00044         z = arg_z.getValue();
00045         w = arg_w.getValue();
00046     } catch ( ArgException &e ) {
00047         std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
00048     }
00049     if ( ( x != 0.0 ) && ( y != 0.0 ) ) {
00050       std::cout << "This quaternion has non-yaw components, aborting." << std::endl;
00051     }
00052     // This is a very naive way of calculating - it is only for the case where it is a
00053     // rotation around a z-axis.
00054     double rads = 2*acos(w)* ecl::sign(z);
00055     double degrees = rads * 360.0 / (2 * ecl::pi);
00056     std::cout << "Quaternion {x: " << x << " y: " << y << " z: " << z << " w: " << w << "} -> ";
00057     std::cout << rads << " radians -> " << degrees << " degrees." << std::endl;
00058 
00059     return 0;
00060 }


ecl_core_apps
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:22:13