38#include <visp3/core/vpMath.h>
39#include <visp3/core/vpQuaternionVector.h>
43const double vpQuaternionVector::minimum = 0.0001;
44const unsigned int vpQuaternionVector::constr_val_4 = 4;
94 const unsigned int index_0 = 0;
95 const unsigned int index_1 = 1;
96 const unsigned int index_2 = 2;
97 const unsigned int index_3 = 3;
138 const unsigned int val_4 = 4;
139 if (q.
size() != val_4) {
141 "Cannot construct a quaternion vector from a %d-dimension col vector", q.
size()));
143 for (
unsigned int i = 0; i < val_4; ++i) {
155 const unsigned int val_4 = 4;
156 if (q.size() != val_4) {
158 "Cannot construct a quaternion vector from a %d-dimension std::vector", q.size()));
161 for (
unsigned int i = 0; i < val_4; ++i) {
178 tu.extract(theta, u);
182 double sinTheta_2 = sin(theta);
183 const unsigned int index_0 = 0;
184 const unsigned int index_1 = 1;
185 const unsigned int index_2 = 2;
186 set(u[index_0] * sinTheta_2, u[index_1] * sinTheta_2, u[index_2] * sinTheta_2, cos(theta));
229 ((
w() * rq.
y()) + (
y() * rq.
w()) + (
z() * rq.
x())) - (
x() * rq.
z()),
230 ((
w() * rq.
z()) + (
z() * rq.
w()) + (
x() * rq.
y())) - (
y() * rq.
x()),
231 ((
w() * rq.
w()) - (
x() * rq.
x()) - (
y() * rq.
y())) - (
z() * rq.
z()));
237 if (
vpMath::nul(l, std::numeric_limits<double>::epsilon())) {
271 const unsigned int val_4 = 4;
272 if (q.
size() != val_4) {
276 for (
unsigned int i = 0; i < val_4; ++i) {
301 double mag_square = (
w() *
w()) + (
x() *
x()) + (
y() *
y()) + (
z() *
z());
302 if (!
vpMath::nul(mag_square, std::numeric_limits<double>::epsilon())) {
306 std::cerr <<
"The current quaternion is null ! The inverse cannot be computed !" << std::endl;
325 if (!
vpMath::nul(mag, std::numeric_limits<double>::epsilon())) {
326 set(
x() / mag,
y() / mag,
z() / mag,
w() / mag);
340 return (q0.
x() * q1.
x()) + (q0.
y() * q1.
y()) + (q0.
z() * q1.
z()) + (q0.
w() * q1.
w());
361#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
385 if (list.size() >
size()) {
388 "Cannot set quaternion vector out of bounds. It has only %d values while you try to initialize with %d values",
389 size(), list.size()));
391 std::copy(list.begin(), list.end(),
data);
412 assert(
t >= 0 &&
t <= 1);
414 double cosHalfTheta =
dot(q0, q1);
416 if (cosHalfTheta < 0) {
417 cosHalfTheta = -cosHalfTheta;
422 qLerp.
x() = q0.
x() - (
t * (q0.
x() - q1.
x()));
423 qLerp.
y() = q0.
y() - (
t * (q0.
y() - q1.
y()));
424 qLerp.
z() = q0.
z() - (
t * (q0.
z() - q1.
z()));
425 qLerp.
w() = q0.
w() - (
t * (q0.
w() - q1.
w()));
446 assert(
t >= 0 &&
t <= 1);
470 assert(
t >= 0 &&
t <= 1);
480 double cosHalfTheta =
dot(q0, q1);
482 if (cosHalfTheta < 0) {
483 cosHalfTheta = -cosHalfTheta;
487 double scale0 = 1 -
t;
490 if ((1 - cosHalfTheta) > 0.1) {
491 double theta = std::acos(cosHalfTheta);
492 double invSinTheta = 1 / std::sin(theta);
494 scale0 = std::sin((1 -
t) * theta) * invSinTheta;
495 scale1 = std::sin(
t * theta) * invSinTheta;
499 qSlerp.
x() = (scale0 * q0.
x()) + (scale1 * q1_.
x());
500 qSlerp.
y() = (scale0 * q0.
y()) + (scale1 * q1_.
y());
501 qSlerp.
z() = (scale0 * q0.
z()) + (scale1 * q1_.
z());
502 qSlerp.
w() = (scale0 * q0.
w()) + (scale1 * q1_.
w());
unsigned int size() const
Return the number of elements of the 2D array.
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
static bool nul(double x, double threshold=0.001)
vpQuaternionVector operator*(double l) const
Multiplication by scalar. Returns a quaternion defined by (lx,ly,lz,lw).
const double & z() const
Returns the z-component of the quaternion.
vpQuaternionVector conjugate() const
vpQuaternionVector inverse() const
vpQuaternionVector & operator=(const vpColVector &q)
void set(double x, double y, double z, double w)
static vpQuaternionVector slerp(const vpQuaternionVector &q0, const vpQuaternionVector &q1, double t)
vpQuaternionVector & buildFrom(const double &qx, const double &qy, const double &qz, const double &qw)
static vpQuaternionVector nlerp(const vpQuaternionVector &q0, const vpQuaternionVector &q1, double t)
vpQuaternionVector operator-() const
Negate operator. Returns a quaternion defined by (-x,-y,-z-,-w).
const double & x() const
Returns the x-component of the quaternion.
static double dot(const vpQuaternionVector &q0, const vpQuaternionVector &q1)
const double & y() const
Returns the y-component of the quaternion.
const double & w() const
Returns the w-component of the quaternion.
vpQuaternionVector operator+(const vpQuaternionVector &q) const
static vpQuaternionVector lerp(const vpQuaternionVector &q0, const vpQuaternionVector &q1, double t)
vpQuaternionVector operator/(double l) const
Division by scalar. Returns a quaternion defined by (x/l,y/l,z/l,w/l).
Implementation of a rotation matrix and operations on such kind of matrices.
vpRotationVector()
Constructor that constructs a 0-size rotation vector.
Implementation of a rotation vector as axis-angle minimal representation.