quaternion2yaw.cpp
Go to the documentation of this file.
1 
7 /*****************************************************************************
8 ** Includes
9 *****************************************************************************/
10 
11 #include <iostream>
12 #include <ecl/command_line.hpp>
13 #include <ecl/linear_algebra.hpp>
14 #include <ecl/math.hpp>
15 
16 /*****************************************************************************
17  * Using
18  ****************************************************************************/
19 
20 using ecl::ArgException;
21 using ecl::CmdLine;
23 
24 /*****************************************************************************
25 ** Main program
26 *****************************************************************************/
27 int main(int argc, char** argv) {
28 
29  /******************************************
30  * Parse for the port name
31  ******************************************/
32  bool hex(false);
33  double x, y, z, w;
34 
35  try {
36  CmdLine cmd("Calculator for yaw to quaternion.",' ',"0.1");
37  UnlabeledValueArg<double> arg_x("x","Quaternion component - x",true,0.0,"float", cmd);
38  UnlabeledValueArg<double> arg_y("y","Quaternion component - y",true,0.0,"float", cmd);
39  UnlabeledValueArg<double> arg_z("z","Quaternion component - z",true,0.0,"float", cmd);
40  UnlabeledValueArg<double> arg_w("w","Quaternion component - w",true,0.0,"float", cmd);
41  cmd.parse(argc,argv);
42  x = arg_x.getValue();
43  y = arg_y.getValue();
44  z = arg_z.getValue();
45  w = arg_w.getValue();
46  } catch ( ArgException &e ) {
47  std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
48  }
49  if ( ( x != 0.0 ) && ( y != 0.0 ) ) {
50  std::cout << "This quaternion has non-yaw components, aborting." << std::endl;
51  }
52  // This is a very naive way of calculating - it is only for the case where it is a
53  // rotation around a z-axis.
54  double rads = 2*acos(w)* ecl::sign(z);
55  double degrees = rads * 360.0 / (2 * ecl::pi);
56  std::cout << "Quaternion {x: " << x << " y: " << y << " z: " << z << " w: " << w << "} -> ";
57  std::cout << rads << " radians -> " << degrees << " degrees." << std::endl;
58 
59  return 0;
60 }
command_line.hpp
ecl::pi
const double pi
ecl::CmdLine
linear_algebra.hpp
ecl::sign
int sign(const Scalar &x)
ecl::ValueArg::getValue
T & getValue()
ecl::ArgException
math.hpp
main
int main(int argc, char **argv)
Definition: quaternion2yaw.cpp:27
ecl::UnlabeledValueArg
ecl::ArgException::argId
std::string argId() const
ecl::ArgException::error
std::string error() const
ecl::CmdLine::parse
void parse(int argc, char **argv)


ecl_core_apps
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:52