@@ -351,9 +351,9 @@ namespace am
351351
352352 }
353353
354- void Rotate::rotate (geometry_msgs::Point32 &p, geometry_msgs::Quaternion &q_rot)
354+ void Rotate::rotate (geometry_msgs::Point32 &p, const geometry_msgs::Quaternion &q_rot)
355355 {
356- geometry_msgs::Point32 old_p;
356+ geometry_msgs::Point32 old_p = p ;
357357 p.x = q_rot.w *q_rot.w *old_p.x + 2 *q_rot.y *q_rot.w *old_p.z - 2 *q_rot.z *q_rot.w *old_p.y + q_rot.x *q_rot.x *old_p.x + 2 *q_rot.y *q_rot.x *old_p.y + 2 *q_rot.z *q_rot.x *old_p.z - q_rot.z *q_rot.z *old_p.x - q_rot.y *q_rot.y *old_p.x ;
358358 p.y = 2 *q_rot.x *q_rot.y *old_p.x + q_rot.y *q_rot.y *old_p.y + 2 *q_rot.z *q_rot.y *old_p.z + 2 *q_rot.w *q_rot.z *old_p.x - q_rot.z *q_rot.z *old_p.y + q_rot.w *q_rot.w *old_p.y - 2 *q_rot.x *q_rot.w *old_p.z - q_rot.x *q_rot.x *old_p.y ;
359359 p.z = 2 *q_rot.x *q_rot.z *old_p.x + 2 *q_rot.y *q_rot.z *old_p.y + q_rot.z *q_rot.z *old_p.z - 2 *q_rot.w *q_rot.y *old_p.x - q_rot.y *q_rot.y *old_p.z + 2 *q_rot.w *q_rot.x *old_p.y - q_rot.x *q_rot.x *old_p.z + q_rot.w *q_rot.w *old_p.z ;
@@ -418,6 +418,50 @@ namespace am
418418 rpy.z = Rotate::toDegree (rpy.z );
419419 }
420420
421+ /*
422+ * @brief transforms a point with the passed transformed stamped
423+ */
424+ void Rotate::transform (geometry_msgs::Point32 &p, const geometry_msgs::TransformStamped &tranform)
425+ {
426+ rotate (p, tranform.transform .rotation );
427+ p.x += tranform.transform .translation .x ;
428+ p.y += tranform.transform .translation .y ;
429+ p.z += tranform.transform .translation .z ;
430+ }
431+
432+ /*
433+ * @brief inverse transform
434+ */
435+ void Rotate::reverse (geometry_msgs::Quaternion &q)
436+ {
437+ double roll, pitch, yaw;
438+ getRPY (q, roll, pitch, yaw);
439+
440+ yaw -= M_PI;
441+ pitch -= M_PI;
442+ roll -=M_PI;
443+
444+ q = toQuaternionMsg (wrap_pi (roll), wrap_pi (pitch), wrap_pi (yaw));
445+ }
446+
447+ /*
448+ * @brief wrap_pi
449+ */
450+ double Rotate::wrap_pi (double angle)
451+ {
452+ while (angle >= M_PI)
453+ {
454+ angle -= 2 * M_PI;
455+ }
456+
457+ while (angle <= -M_PI)
458+ {
459+ angle += 2 * M_PI;
460+ }
461+
462+ return angle;
463+ }
464+
421465}
422466
423467
0 commit comments