36 double sinr = +2.0 * (
q->qw *
q->qx +
q->qy *
q->qz);
37 double cosr = +1.0 - 2.0 * (
q->qx *
q->qx +
q->qy *
q->qy);
38 double roll = atan2(sinr, cosr);
40 double sinp = +2.0 * (
q->qw *
q->qy -
q->qz *
q->qx);
44 pitch = copysign(
M_PI / 2, sinp);
51 double siny = +2.0 * (
q->qw *
q->qz +
q->qx *
q->qy);
52 double cosy = +1.0 - 2.0 * (
q->qy *
q->qy +
q->qz *
q->qz);
53 double yaw = atan2(siny, cosy);
54 return {roll, pitch, yaw};
61 double cy = cos(yaw * 0.5);
62 double sy = sin(yaw * 0.5);
63 double cr = cos(roll * 0.5);
64 double sr = sin(roll * 0.5);
65 double cp = cos(pitch * 0.5);
66 double sp = sin(pitch * 0.5);
67 q->qw = cy * cr * cp + sy * sr * sp;
68 q->qx = cy * sr * cp - sy * cr * sp;
69 q->qy = cy * cr * sp + sy * sr * cp;
70 q->qz = sy * cr * cp - cy * sr * sp;
76 return Eigen::Quaternion<double>(
q->qw,
q->qx,
q->qy,
q->qz);