14#include <Eigen/Eigenvalues>
41 for (
size_t i = 0; i < l; i++) {
57 for (
size_t k = 0; k < s; k++) {
74 for (
size_t r = 0; r < m; r++) {
75 for (
size_t c = 0; c < n; c++) {
92 for (
size_t i = 0; i < l; i++) {
101 for (
size_t i = 0; i < l; i++) {
117 for (
size_t k = 0; k < s; k++) {
135 for (
size_t r = 0; r < m; r++) {
136 for (
size_t c = 0; c < n; c++) {
156 size_t size=a.
size();
157 for (
size_t i = 0; i < size; i++) {
228 for (
size_t r = 0; r < M.
rows(); r++) {
229 for (
size_t c = 0; c < M.
cols(); c++) {
246 for (
size_t i = 0; i < n; i++) {
255 a.
w()*b.
y() + a.
y()*b.
w() + a.
z()*b.
x() - a.
x()*b.
z(),
256 a.
w()*b.
z() + a.
z()*b.
w() + a.
x()*b.
y() - a.
y()*b.
x(),
257 a.
w()*b.
w() - a.
x()*b.
x() - a.
y()*b.
y() - a.
z()*b.
z());
270 for (
size_t i = 0; i < n; i++) {
286 for (
size_t i = 0; i < n; i++) {
303 for (
int r = 0; r < rows; r++) {
304 for (
int c = 0; c < cols; c++) {
313 size_t c = m1.
cols();
315 size_t r1 = m1.
rows();
316 size_t r2 = m2.
rows();
353 size_t n = v1.
size();
365 size_t r = m1.
rows();
367 size_t c1 = m1.
cols();
368 size_t c2 = m2.
cols();
405 size_t n1 = v1.
size();
406 size_t n2 = v2.
size();
488 for (
size_t i = 0; i < s; i++) {
489 for (
size_t j = 0; j < s; j++) {
490 res(i, j) = a(i) * b(j);
501 v[0]=a[1]*b[2]-a[2]*b[1];
502 v[1]=a[2]*b[0]-a[0]*b[2];
503 v[2]=a[0]*b[1]-a[1]*b[0];
525 if (res.
cols() != 3 || res.
rows() != 3) {
528 res(0,0) = res(1,1) = res(2,2) = 0.0;
554 for (
size_t i = 1; i < v.
size(); i++) {
568 for (
size_t i = 1; i < v.
length(); i++) {
609 return toEigen(in).determinant();
636 Eigen::EigenSolver< Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> > es(
toEigen(in));
638 for(
int i=0; i < n; i++)
640 std::complex<double> lambda = es.eigenvalues()[i];
641 real(i) = lambda.real();
642 img(i) = lambda.imag();
659 return ((v==0.0)?0.0:((v>0.0)?1.0:-1.0));
666 for (
size_t i = 0; i < v.
length(); i++) {
683 double theta=atan2(0.5*r,0.5*(R(0,0)+R(1,1)+R(2,2)-1));
758 bool singularity=
false;
763 v[0]=atan2(R(1,2),R(0,2));
765 v[2]=atan2(R(2,1),-R(2,0));
771 v[0]=-atan2(R(1,0),R(1,1));
780 v[0]=atan2(R(1,0),R(1,1));
786 yCWarning(MATH,
"dcm2euler() in singularity: choosing one solution among multiple");
797 double alpha=v[0];
double ca=cos(alpha);
double sa=sin(alpha);
798 double beta=v[1];
double cb=cos(beta);
double sb=sin(beta);
799 double gamma=v[2];
double cg=cos(gamma);
double sg=sin(gamma);
801 Rza(0,0)=ca; Rza(1,1)=ca; Rza(1,0)= sa; Rza(0,1)=-sa;
802 Rzg(0,0)=cg; Rzg(1,1)=cg; Rzg(1,0)= sg; Rzg(0,1)=-sg;
803 Ryb(0,0)=cb; Ryb(2,2)=cb; Ryb(2,0)=-sb; Ryb(0,2)= sb;
813 bool singularity=
false;
818 v[0]=atan2(R(2,1),R(2,2));
820 v[2]=atan2(R(1,0),R(0,0));
828 v[2]=-atan2(-R(1,2),R(1,1));
837 v[2]=atan2(-R(1,2),R(1,1));
841 yCWarning(MATH,
"dcm2rpy() in singularity: choosing one solution among multiple");
852 double roll=v[0];
double cr=cos(roll);
double sr=sin(roll);
853 double pitch=v[1];
double cp=cos(pitch);
double sp=sin(pitch);
854 double yaw=v[2];
double cy=cos(yaw);
double sy=sin(yaw);
856 Rz(0,0)=cy; Rz(1,1)=cy; Rz(0,1)=-sy; Rz(1,0)= sy;
857 Ry(0,0)=cp; Ry(2,2)=cp; Ry(0,2)= sp; Ry(2,0)=-sp;
858 Rx(1,1)=cr; Rx(2,2)=cr; Rx(1,2)=-sr; Rx(2,1)= sr;
873 v[0] = atan2(-R(0, 1), R(0, 0));
874 v[1] = asin(R(0, 2));
875 v[2] = atan2(-R(1, 2), R(2, 2));
882 v[2] = -atan2(R(1, 0), R(1, 1));
890 v[2] = atan2(R(1, 0), R(1, 1));
901 double roll = v[2];
double cr = cos(roll);
double sr = sin(roll);
902 double pitch = v[1];
double cp = cos(pitch);
double sp = sin(pitch);
903 double yaw = v[0];
double cy = cos(yaw);
double sy = sin(yaw);
905 Rz(0, 0) = cy; Rz(1, 1) = cy; Rz(0, 1) = -sy; Rz(1, 0) = sy;
906 Ry(0, 0) = cp; Ry(2, 2) = cp; Ry(0, 2) = sp; Ry(2, 0) = -sp;
907 Rx(1, 1) = cr; Rx(2, 2) = cr; Rx(1, 2) = -sr; Rx(2, 1) = sr;
928 invH(3,0)=invH(3,1)=invH(3,2)=0.0;
939 S(0,0)= 0.0; S(0,1)=-H(2,3); S(0,2)= H(1,3);
940 S(1,0)= H(2,3); S(1,1)= 0.0; S(1,2)=-H(0,3);
941 S(2,0)=-H(1,3); S(2,1)= H(0,3); S(2,2)= 0.0;
946 for (
int i=0; i<3; i++)
948 for (
int j=0; j<3; j++)
969 S(0,0)= 0.0; S(0,1)=-Rtp(2); S(0,2)= Rtp(1);
970 S(1,0)= Rtp(2); S(1,1)= 0.0; S(1,2)=-Rtp(0);
971 S(2,0)=-Rtp(1); S(2,1)= Rtp(0); S(2,2)= 0.0;
976 for (
int i=0; i<3; i++)
978 for (
int j=0; j<3; j++)
981 A(i+3,j+3) = Rt(i,j);
void zero()
Zero the matrix.
Matrix submatrix(size_t r1, size_t r2, size_t c1, size_t c2) const
Extract a submatrix from (r1,c1) to (r2,c2) (extremes included), as in Matlab B=A(r1:r2,...
void resize(size_t r, size_t c)
Resize the matrix, if matrix is not empty preserve old content.
Matrix transposed() const
Return the transposed of the matrix.
size_t cols() const
Return number of columns.
Vector getCol(size_t c) const
Get a columns of the matrix as a vector.
size_t rows() const
Return number of rows.
void resize(size_t size) override
Resize the vector.
VectorOf< T > subVector(unsigned int first, unsigned int last) const
Creates and returns a new vector, being the portion of the original vector defined by the first and l...
size_t length() const
Get the length of the vector.
#define yCAssert(component, x)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
Vector operator+(const Vector &a, const double &s)
Mathematical operations.
Vector operator-(const Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Vector operator*(double k, const Vector &b)
Scalar-vector product operator (defined in Math.h).
Vector & operator-=(Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
Vector & operator/=(Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
Vector operator/(const Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
Vector & operator*=(Vector &a, double k)
Vector-scalar product operator (defined in Math.h).
yarp::rosmsg::geometry_msgs::Quaternion Quaternion
Eigen::Map< Eigen::VectorXd > toEigen(yarp::sig::Vector &yarpVector)
Convert a yarp::sig::Vector to a Eigen::Map<Eigen::VectorXd> object.
yarp::sig::Matrix eye(int r, int c)
Build an identity matrix (defined in Math.h).
void SVD(const yarp::sig::Matrix &in, yarp::sig::Matrix &U, yarp::sig::Vector &S, yarp::sig::Matrix &V)
Factorize the M-by-N matrix 'in' into the singular value decomposition in = U S V^T (defined in SVD....
yarp::sig::Matrix cat(const yarp::sig::Matrix &m1, const yarp::sig::Matrix &m2)
Matrix-Matrix concatenation by row (defined in Math.h).
double norm(const yarp::sig::Vector &v)
Returns the Euclidean norm of the vector (defined in Math.h).
yarp::sig::Vector cross(const yarp::sig::Vector &a, const yarp::sig::Vector &b)
Compute the cross product between two vectors (defined in Math.h).
yarp::sig::Vector ones(int s)
Creates a vector of ones (defined in Math.h).
yarp::sig::Vector dcm2ypr(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix to yaw-roll-pitch angles (defined in Math....
bool eigenValues(const yarp::sig::Matrix &in, yarp::sig::Vector &real, yarp::sig::Vector &img)
Computes eigenvalues of the n-by-n real nonsymmetric matrix (defined in Math.h).
yarp::sig::Matrix crossProductMatrix(const yarp::sig::Vector &v)
Compute the cross product matrix, that is a 3-by-3 skew-symmetric matrix (defined in Math....
double norm2(const yarp::sig::Vector &v)
Returns the Euclidean squared norm of the vector (defined in Math.h).
double det(const yarp::sig::Matrix &in)
Computes the determinant of a matrix (defined in Math.h).
yarp::sig::Matrix SE3inv(const yarp::sig::Matrix &H)
Returns the inverse of a 4 by 4 rototranslational matrix (defined in Math.h).
yarp::sig::Matrix adjointInv(const yarp::sig::Matrix &H)
Returns the inverse of the adjoint matrix of a given roto-translational matrix (defined in Math....
yarp::sig::Vector zeros(int s)
Creates a vector of zeros (defined in Math.h).
double findMax(const yarp::sig::Vector &v)
Returns the maximum of the elements of a real vector (defined in Math.h).
yarp::sig::Matrix rpy2dcm(const yarp::sig::Vector &rpy)
Converts roll-pitch-yaw angles in the corresponding dcm (direction cosine matrix) rotation matrix (de...
double sign(const double &v)
Invert a symmetric and positive definite matrix using Cholesky decomposition (defined in Math....
double findMin(const yarp::sig::Vector &v)
Returns the minimum of the elements of a real vector (defined in Math.h).
yarp::sig::Matrix adjoint(const yarp::sig::Matrix &H)
Returns the adjoint matrix of a given roto-translational matrix (defined in Math.h).
yarp::sig::Matrix ypr2dcm(const yarp::sig::Vector &ypr)
Converts yaw-pitch-roll angles in the corresponding dcm (direction cosine matrix) rotation matrix (de...
double dot(const yarp::sig::Vector &a, const yarp::sig::Vector &b)
Scalar product between vectors (defined in Math.h).
yarp::sig::Vector dcm2euler(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix to euler angles (ZYZ) (defined in Math....
yarp::sig::Matrix axis2dcm(const yarp::sig::Vector &v)
Returns a dcm (direction cosine matrix) rotation matrix R from axis/angle representation (defined in ...
yarp::sig::Matrix luinv(const yarp::sig::Matrix &in)
Invert a square matrix using LU-decomposition (defined in Math.h).
yarp::sig::Matrix euler2dcm(const yarp::sig::Vector &euler)
Converts euler angles (ZYZ) vector in the corresponding dcm (direction cosine matrix) rotation matrix...
yarp::sig::Vector dcm2rpy(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix to roll-pitch-yaw angles (defined in Math....
yarp::sig::Matrix outerProduct(const yarp::sig::Vector &a, const yarp::sig::Vector &b)
Outer product between vectors (defined in Math.h).
yarp::sig::Matrix pile(const yarp::sig::Matrix &m1, const yarp::sig::Matrix &m2)
Matrix-Matrix concatenation by column (defined in Math.h).
yarp::sig::Vector dcm2axis(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix R to axis/angle representation (defined in M...
VectorOf< double > Vector