latest version v1.9 - last update 10 Apr 2010 |
This class transforms the coordinates of a 3D point between two coordinate systems. More...
#include <ltiCoordinateTransformation.h>
Classes | |
class | parameters |
------------------------------------------------------------------ start of parameters The parameters for the class coordinateTransformation More... | |
Public Member Functions | |
coordinateTransformation () | |
coordinateTransformation (const parameters &par) | |
coordinateTransformation (const coordinateTransformation &other) | |
virtual | ~coordinateTransformation () |
virtual const char * | getTypeName () const |
bool | apply (vector< float > &srcdest) const |
bool | apply (const vector< float > &src, vector< float > &dest) const |
coordinateTransformation & | copy (const coordinateTransformation &other) |
coordinateTransformation & | operator= (const coordinateTransformation &other) |
virtual functor * | clone () const |
const parameters & | getParameters () const |
This class transforms the coordinates of a 3D point between two coordinate systems.
These two coordinate systems are both of cartesian type, but they are rotated and/or displaced to each other.
Inner- vs. Outer-coordinate-system:
The two systems will be called outer- and the inner-coordinate- system. The inner system is rotated and/or displaced to the outer one. Let's take a look at a common example. We have a room which is our global reference frame. A mobile robot can be navigated in this room. On top of the robot, a stereo-camera is placed on a pan-tilt unit.
Our goal is to transform a point from the cameras coordinate system to the global reference frame. To do this we need two instances of this class.
1. the camera and the robot: the camera is the inner system and the robot is the outer system. The inner system has a fixed displacement and a variable orientation, which can be changed by the pan-tilt unit.
2. the robot and the room: here the robot is the inner system and the room is the outer one.
To perform a transformation, we need the following parameters (all float ):
It is important, that you rotate your inner coordinate system axis in the right-hand-screw-rule in chronological order!
That means:
Take your right hand (difficult job) and orientate your thumb in the positive direction of the inner-axis around which you want to rotate. When your remaining fingers are not racked, they will point around this axis and point in direction of positive angles.
Attention:
Rotating in chronological order means to rotate the axis in the order x, y, z. Otherwise you will get wrong results. If you rotate around all three axis, beta and gamma can not be seen directly, so you definitely have to calculate the angles one after the other.
Here is how the transformation is performed:
For each angle / axis-rotation, a rotation matrix will be calculated. Matrix A contains the rotation around the x axis, B around y and C around z. The transformed vector vT
arises by multiplying the untransformed vector v
with these matrices: vT = C*B*A*v + displacement.
In order to save calculation time for subsequent transformations, the three matrices will be multiplied to D=C*B*A, hence only the following will be computed when you call the apply-method: vT = D*v + displacement.
Here is how to set/initialize the parameters: After creating an object of the parameter class you have to call the function coordinateTransformation::parameters::initParameters to set/initialize the parameters.. In this method, the rotation matrix D will be calculated. Take a look at the code example below.
Alternatives:
Example:
We have a robot with a stereo camera on it, which is standing in a room (our global reference frame). 1. The camera is placed 0.3 meters right and 0.25 meters in front of the origin of our global reference frame. 2. The robot points in z-direction, the y-axis of our global frame points to the ceiling, so the x-axis points to the left. 3. The camera looks 15 degrees to the right and 45 degrees to the ground.
Our displacement-vector is: (-0.3, 0, 0.25). To get the rotation-angles we first have to rotate the camera around the x-axis:
=> alpha = -45 degrees.
Then we have to rotate around the y-axis:
=> beta = +15 degrees.
We do not have a rotation around z.
So here is the code:
lti::coordinateTransformation coordTransform; lti::coordinateTransformation::parameters transformParam; float fSystemsDisplacement[3] = {-0.3, 0, 0.25}; lti::vector<float> vDisplace(3,fSystemsDisplacement); transformParam.initParameters(-45, 15, 0, vDisplace); coordTransform.setParameters(transformParam); float fPoint[3] = {u, v, w}; lti::vector<float> vPoint(3,fPoint); std::cout << "The point: " << vPoint << " in the inner system:" << std::endl; coordTransform.apply(vPoint); std::cout << "has the position :" << vPoint << " in the outer system." << std::endl;
lti::coordinateTransformation::coordinateTransformation | ( | ) |
------------------------------------------------------------------ End of Parameters
Default constructor
lti::coordinateTransformation::coordinateTransformation | ( | const parameters & | par | ) |
Construct a functor using the given parameters.
lti::coordinateTransformation::coordinateTransformation | ( | const coordinateTransformation & | other | ) |
Copy constructor.
other | the object to be copied |
virtual lti::coordinateTransformation::~coordinateTransformation | ( | ) | [virtual] |
Destructor.
bool lti::coordinateTransformation::apply | ( | const vector< float > & | src, | |
vector< float > & | dest | |||
) | const |
bool lti::coordinateTransformation::apply | ( | vector< float > & | srcdest | ) | const |
virtual functor* lti::coordinateTransformation::clone | ( | ) | const [virtual] |
Returns a pointer to a clone of this functor.
Implements lti::functor.
coordinateTransformation& lti::coordinateTransformation::copy | ( | const coordinateTransformation & | other | ) |
Copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::functor.
const parameters& lti::coordinateTransformation::getParameters | ( | ) | const |
Returns used parameters.
Reimplemented from lti::functor.
virtual const char* lti::coordinateTransformation::getTypeName | ( | ) | const [virtual] |
Returns the name of this type ("coordinateTransformation").
Reimplemented from lti::linearAlgebraFunctor.
coordinateTransformation& lti::coordinateTransformation::operator= | ( | const coordinateTransformation & | other | ) |