YARP
Yet Another Robot Platform
Quaternion.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_QUATERNION
7 #define YARP_QUATERNION
8 
9 #include <yarp/math/api.h>
10 #include <yarp/sig/Vector.h>
11 #include <yarp/sig/Matrix.h>
12 #include <yarp/os/Portable.h>
13 
14 // network stuff
15 #include <yarp/os/NetInt32.h>
16 
17 namespace yarp {
18  namespace math {
19  class Quaternion;
20  }
21 }
22 
24 {
25  double internal_data[4]; // stored as [w x y z]
26 
27 public:
28  Quaternion();
29  Quaternion(double x, double y, double z, double w);
30  double* data();
31  const double* data() const;
32  double x() const;
33  double y() const;
34  double z() const;
35  double w() const;
36  double& x() ;
37  double& y() ;
38  double& z() ;
39  double& w() ;
40 
41  std::string toString(int precision = -1, int width = -1) const;
42 
46  double abs();
47 
51  void normalize();
52 
56  bool isValid() const;
57 
61  Quaternion inverse() const;
62 
66  double arg();
67 
72  void fromAxisAngle(const yarp::sig::Vector &v);
73 
79  void fromAxisAngle(const yarp::sig::Vector& axis, const double& angle);
80 
81 
83 
108  void fromRotationMatrix(const yarp::sig::Matrix &R);
109 
110 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
116  YARP_DEPRECATED_MSG("Use toRotationMatrix4x4 instead")
118 #endif
119 
146 
153 
157  yarp::sig::Vector toVector() const;
158 
160  /*
161  * Read vector from a connection.
162  * return true iff a vector was read correctly
163  */
164  bool read(yarp::os::ConnectionReader& connection) override;
165 
170  bool write(yarp::os::ConnectionWriter& connection) const override;
171 
172  yarp::os::Type getType() const override
173  {
174  return yarp::os::Type::byName("yarp/quaternion");
175  }
176 
177 
178 };
179 
180 #endif
contains the definition of a Matrix type
contains the definition of a Vector type
void fromRotationMatrix(const yarp::sig::Matrix &R)
Converts a rotation matrix to a quaternion.
Definition: Quaternion.cpp:162
double abs()
Computes the modulus of the quaternion.
Definition: Quaternion.cpp:313
double x() const
Definition: Quaternion.cpp:81
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Quaternion.cpp:116
yarp::sig::Vector toVector() const
Converts the quaternion to a vector of length 4.
Definition: Quaternion.cpp:66
yarp::sig::Matrix toRotationMatrix3x3() const
Converts a quaternion to a rotation matrix.
Definition: Quaternion.cpp:241
Quaternion inverse() const
Computes the inverse of the quaternion.
Definition: Quaternion.cpp:339
std::string toString(int precision=-1, int width=-1) const
Definition: Quaternion.cpp:260
void normalize()
Normalizes the quaternion elements.
Definition: Quaternion.cpp:321
void fromAxisAngle(const yarp::sig::Vector &v)
Computes the quaternion from an axis-angle representation.
Definition: Quaternion.cpp:282
double arg()
Computes the argument or phase of the quaternion in radians.
Definition: Quaternion.cpp:331
yarp::os::Type getType() const override
Definition: Quaternion.h:172
yarp::sig::Matrix toRotationMatrix4x4() const
Converts a quaternion to a rotation matrix.
Definition: Quaternion.cpp:222
double z() const
Definition: Quaternion.cpp:91
double w() const
Definition: Quaternion.cpp:76
yarp::sig::Vector toAxisAngle()
Definition: Quaternion.cpp:306
bool isValid() const
Check if the quaternion is valid.
Definition: Quaternion.cpp:57
bool write(yarp::os::ConnectionWriter &connection) const override
Write vector to a connection.
Definition: Quaternion.cpp:141
double y() const
Definition: Quaternion.cpp:86
yarp::sig::Matrix toRotationMatrix() const
Converts a quaternion to a rotation matrix.
Definition: Quaternion.h:117
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:26
static Type byName(const char *name)
Definition: Type.cpp:171
A class for a Matrix.
Definition: Matrix.h:43
yarp::rosmsg::geometry_msgs::Quaternion Quaternion
Definition: Quaternion.h:21
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_math_API
Definition: api.h:17