forked from FreeCAD/FreeCAD
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Rotation.h
123 lines (108 loc) · 5.27 KB
/
Rotation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/***************************************************************************
* Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef BASE_ROTATION_H
#define BASE_ROTATION_H
#include "Vector3D.h"
namespace Base {
// forward declarations
class Matrix4D;
class BaseExport Rotation
{
public:
/** Construction. */
//@{
Rotation();
Rotation(const Vector3d& axis, const double fAngle);
Rotation(const Matrix4D& matrix);
Rotation(const double q[4]);
Rotation(const double q0, const double q1, const double q2, const double q3);
Rotation(const Vector3d& rotateFrom, const Vector3d& rotateTo);
Rotation(const Rotation& rot);
//@}
/** Methods to get or set rotations. */
//@{
const double * getValue(void) const;
void getValue(double & q0, double & q1, double & q2, double & q3) const;
void setValue(const double q0, const double q1, const double q2, const double q3);
/// If not a null quaternion then \a axis will be normalized
void getValue(Vector3d & axis, double & rfAngle) const;
/// Does the same as the method above unless normalizing the axis.
void getRawValue(Vector3d & axis, double & rfAngle) const;
void getValue(Matrix4D & matrix) const;
void setValue(const double q[4]);
void setValue(const Matrix4D& matrix);
void setValue(const Vector3d & axis, const double fAngle);
void setValue(const Vector3d & rotateFrom, const Vector3d & rotateTo);
/// Euler angles in yaw,pitch,roll notation
void setYawPitchRoll(double y, double p, double r);
/// Euler angles in yaw,pitch,roll notation
void getYawPitchRoll(double& y, double& p, double& r) const;
bool isIdentity() const;
bool isNull() const;
//@}
/** Invert rotations. */
//@{
Rotation & invert(void);
Rotation inverse(void) const;
//@}
/** Operators. */
//@{
Rotation & operator*=(const Rotation & q);
Rotation operator *(const Rotation & q) const;
bool operator==(const Rotation & q) const;
bool operator!=(const Rotation & q) const;
double & operator [] (unsigned short usIndex){return quat[usIndex];}
const double & operator [] (unsigned short usIndex) const{return quat[usIndex];}
void operator = (const Rotation&);
void multVec(const Vector3d & src, Vector3d & dst) const;
Vector3d multVec(const Vector3d & src) const;
void scaleAngle(const double scaleFactor);
bool isSame(const Rotation&) const;
bool isSimilar(const Rotation&, double tol) const;
//@}
/** Specialty constructors */
static Rotation slerp(const Rotation & rot0, const Rotation & rot1, double t);
static Rotation identity(void);
/**
* @brief makeRotationByAxes(xdir, ydir, zdir, priorityOrder): creates a rotation
* that converts a vector in local cs with axes given as arguments, into a
* vector in global cs.
* @param xdir is wanted direction of local X axis
* @param ydir ...
* @param zdir
* @param priorityOrder sets which directions are followed. It is a string
* like "ZXY". This means, Z direction is followed precisely; X direction is
* corrected to be perpendicular to Z direction, and used; Y direction
* argument is ignored altogether (Y direction is generated from Z and X).
*
* If only one vector provided is nonzero, the other two directions are picked automatically.
*/
static Rotation makeRotationByAxes(Vector3d xdir, Vector3d ydir, Vector3d zdir, const char* priorityOrder = "ZXY");
private:
void normalize();
void evaluateVector ();
double quat[4];
Vector3d _axis; // the axis kept not to lose direction when angle is 0
double _angle; // this angle to keep the angle chosen by the user
};
}
#endif // BASE_ROTATION_H