MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
eu2phi.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/utils/eu2phi.cc,v 1.17 2017/01/12 15:10:27 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  *
10  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
11  * via La Masa, 34 - 20156 Milano, Italy
12  * http://www.aero.polimi.it
13  *
14  * Changing this copyright notice is forbidden.
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation (version 2 of the License).
19  *
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  *
30  * This file is copyrighted by:
31  * Alessandro Fumagalli < alessandro.fumagalli@polimi.it >
32  */
33 
34 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
35 
36 #include <cstring>
37 #include <stdlib.h>
38 #include <string>
39 #include <iostream>
40 
41 #include "matvec3.h"
42 #include "matvecexp.h"
43 #include "Rot.hh"
44 
45 int
46 main(int argn, const char* const argv[])
47 {
48  bool v = false;
49  if (argn > 1) {
50  if (!strcasecmp(argv[1], "-?")
51  || !strcasecmp(argv[1], "-h")
52  || !strcasecmp(argv[1], "--help")) {
53  std::cerr << std::endl
54  << "usage: " << argv[0] << "[-v]" << std::endl
55  << std::endl
56  << " reads the Euler angles (in degs)"
57  " from stdin;" << std::endl
58  << " writes the rotation vector {magniture (in degs), direction} on standard output"
59  << std::endl
60  << " -v: write the rotation vector (in rads) instead of magnitude, direction"
61  << std::endl
62  << std::endl
63  << "part of MBDyn package (Copyright (C)"
64  " Pierangelo Masarati, 1996-2006)" << std::endl
65  << " Authors: Alessandro Fumagalli" << std::endl
66  << " Marco Morandini" << std::endl
67  << std::endl;
68  exit(EXIT_SUCCESS);
69  } else {
70  if (!strcasecmp(argv[1], "-v")) {
71  v = true;
72  }
73  }
74  }
75 
76  std::cout.precision(16);
77 
78  static doublereal d[3];
79  while (true) {
80  std::cin >> d[0];
81  if (std::cin) {
82  std::cin >> d[1] >> d[2];
83 
84  Mat3x3 R(EulerAngles2MatR(Vec3(d)/(180./M_PI)));
85  Vec3 phi(RotManip::VecRot(R));
86 
87  if (v) {
88  std::cout << phi << std::endl;
89  } else {
90  doublereal D = phi.Norm();
91  if (D != 0.) {
92  std::cout << D*180./M_PI << " " << phi/D << std::endl;
93  } else {
94  std::cout << 0. << " " << 0. << " " << 0. << " " << 0. << std::endl;
95  }
96  }
97  } else {
98  break;
99  }
100  }
101 
102  return EXIT_SUCCESS;
103 }
104 
#define M_PI
Definition: gradienttest.cc:67
Definition: matvec3.h:98
doublereal Norm(void) const
Definition: matvec3.h:263
int main(int argn, const char *const argv[])
Definition: eu2phi.cc:46
Vec3 VecRot(const Mat3x3 &Phi)
Definition: Rot.cc:136
Mat3x3 EulerAngles2MatR(const Vec3 &v)
Definition: matvec3.cc:1008
double doublereal
Definition: colamd.c:52
Mat3x3 R