#include <HomogeneousTransform.hpp>
Public Member Functions | |
HomogeneousTransform () | |
void | concatenate (const HomogeneousTransform &transform) |
void | perspectiveZ (double f) |
void | rotateX (double cos, double sin) |
void | rotateY (double cos, double sin) |
void | rotateZ (double cos, double sin) |
void | scale (double x, double y, double z) |
void | transform (double x, double y, double z, double w, double &outx, double &outy, double &outz, double &outw) const |
Vec | transform (Vec p) const |
void | translate (double x, double y, double z) |
Private Attributes | |
double | M [4][4] |
Consider homogeneous coordinates \((x,y,z,w)\) with arbitrary scale factor \(w\). An arbitary point \(\mathbf{P}=(P_{x},P_{y},P_{z})\) can be represented in homogeneous coordinates as \(\mathcal{P}=(P_{x},P_{y},P_{z},1)\). An arbitrary direction \(\mathbf{D}=(D_{x},D_{y},D_{z})\) is represented as a point at infinity \(\mathcal{D}=(D_{x},D_{y},D_{z},0)\).
Vice versa, given the homogeneous coordinates \(\mathcal{Q}=(Q_{x},Q_{y},Q_{z},Q_{w})\), the corresponding regular coordinates for the point can be retrieved as \(\mathbf{Q}=(Q_{x}/Q_{w},Q_{y}/Q_{w},Q_{z}/Q_{w})\) provided \(Q_{w}\neq0\).
A homogeneous coordinate transformation can be written as \(\mathcal{P}'=\mathcal{P}\,\mathcal{T}\) where \(\mathcal{T}\) is a \(4\times4\) transformation matrix which can represent a scaling, rotation, translation, perspective transformation or any combination thereof; or more explicitly
\[ \left[\begin{array}{cccc} x' & y' & z' & w'\end{array}\right]=\left[\begin{array}{cccc} x & y & z & w\end{array}\right]\left[\begin{array}{cccc} t_{11} & t_{12} & t_{13} & t_{14}\\ t_{21} & t_{22} & t_{23} & t_{24}\\ t_{31} & t_{32} & t_{33} & t_{34}\\ t_{41} & t_{42} & t_{43} & t_{44} \end{array}\right] \]
A HomogeneousTransform instance represents the \(4\times4\) matrix specifying a homogeneous coordinate transform. The constructor creates an identity transform, and various functions serve to concatenate specific transforms to the current one. Finally, the transform() function actually computes the transformation for given homogeneous coordinates.
HomogeneousTransform::HomogeneousTransform | ( | ) |
The default constructor; it creates an identity transform.
void HomogeneousTransform::concatenate | ( | const HomogeneousTransform & | transform | ) |
This function concatenates the specified tranform to the current transform.
void HomogeneousTransform::perspectiveZ | ( | double | f | ) |
This function concatenates to the current transform a perspective along the z axis with the specified focal length.
void HomogeneousTransform::rotateX | ( | double | cos, |
double | sin | ||
) |
This function concatenates to the current transform a rotation about the x axis over an angle \(\alpha\) specified through the values \(\cos\alpha\) and \(\sin\alpha\). It is the caller's responsibility to ensure that \(\cos^2\alpha+\sin^2\alpha=1\) holds for the values passed to this function.
void HomogeneousTransform::rotateY | ( | double | cos, |
double | sin | ||
) |
This function concatenates to the current transform a rotation about the y axis over an angle \(\alpha\) specified through the values \(\cos\alpha\) and \(\sin\alpha\). It is the caller's responsibility to ensure that \(\cos^2\alpha+\sin^2\alpha=1\) holds for the values passed to this function.
void HomogeneousTransform::rotateZ | ( | double | cos, |
double | sin | ||
) |
This function concatenates to the current transform a rotation about the z axis over an angle \(\alpha\) specified through the values \(\cos\alpha\) and \(\sin\alpha\). It is the caller's responsibility to ensure that \(\cos^2\alpha+\sin^2\alpha=1\) holds for the values passed to this function.
void HomogeneousTransform::scale | ( | double | x, |
double | y, | ||
double | z | ||
) |
This function concatenates to the current transform a scaling by the specified factor along each coordinate axis.
void HomogeneousTransform::transform | ( | double | x, |
double | y, | ||
double | z, | ||
double | w, | ||
double & | outx, | ||
double & | outy, | ||
double & | outz, | ||
double & | outw | ||
) | const |
This function applies the current transform to the specified homogeneous coordinates and stores the result in homogeneous coordinates in the output variables.
This function applies the current transform to a position vector specified in regular coordinates and returns the transformed position vector in regular coordinates. If the transformed position is at infinity, the value of the returned vector is undefined.
void HomogeneousTransform::translate | ( | double | x, |
double | y, | ||
double | z | ||
) |
This function concatenates to the current transform a translation over the specified offset along each coordinate axis.