Skip to content

Commit

Permalink
Added global-to-local and local-to-global transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
ilpincy committed Sep 22, 2023
1 parent 43d00f3 commit 3ba6c16
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ set(ARGOS3_HEADERS_UTILITY_MATH
utility/math/ray3.h
utility/math/rng.h
utility/math/pose2.h
utility/math/transforms.h
utility/math/vector2.h
utility/math/vector3.h)
# argos3/core/utility/math/matrix
Expand Down Expand Up @@ -155,6 +156,7 @@ set(ARGOS3_SOURCES_CORE
utility/math/cylinder.cpp
utility/math/convex_hull.cpp
utility/math/pose2.cpp
utility/math/transforms.h
utility/math/vector2.cpp
utility/math/vector3.cpp
utility/math/plane.cpp
Expand Down
29 changes: 29 additions & 0 deletions src/core/utility/math/transforms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "transforms.h"

using namespace argos;

/****************************************/
/****************************************/

CVector3 GlobalToLocal(const CVector3& c_global,
const CVector3& c_translation,
const CQuaternion& c_orientation) {
CVector3 cLocal = c_global - c_translation;
cLocal.Rotate(c_orientation.Inverse());
return cLocal;
}

/****************************************/
/****************************************/

CVector3 LocalToGlobal(const CVector3& c_local,
const CVector3& c_translation,
const CQuaternion& c_orientation) {
CVector cGlobal = c_local.Rotate(c_orientation);
cGlobal += c_translation;
return cGlobal;
}

/****************************************/
/****************************************/

16 changes: 16 additions & 0 deletions src/core/utility/math/transforms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TRANSFORMS_H
#define TRANSFORMS_H

namespace argos {

CVector3 GlobalToLocal(const CVector3& c_global,
const CVector3& c_translation,
const CQuaternion& c_orientation);

CVector3 LocalToGlobal(const CVector3& c_local,
const CVector3& c_translation,
const CQuaternion& c_orientation);

}

#endif // TRANSFORMS_H

0 comments on commit 3ba6c16

Please sign in to comment.