Geometrical transformations#
The base class for geomtrical transformations is Transformation. It can be a canonical transformation or a composition of transformations.
Canonical transformations#
In the following, we will consider straight lines and planes. A straight line is fully defined by a point and a direction. The latter is a vector of components (2 or 3). This is a reason why we will write a straight line as follows : \(\left(\Omega, \vec{d}\right)\). A plane is fully defined by a point and a normal vector. This is a reason why we will write a plane as follows : \(\left[\Omega, \vec{n}\right]\).
All canonical transformations are related to classes inheriting from the Transformation class.
Translations#
Point B is the image of point A by a translation of vector \(\vec{u}\) if and only if
A translation can be defined by a vector (size 2 or 3) or by its components:
Reals u;
Real ux, uy, uz;
Translation t1(_direction=u), t2(_direction={ux, uy}), t3(_direction={ux, uy, uz});
Important
The default direction vector is the 3d zero vector (no transform)
2d rotations#
Point B is the image of point A by the 2d rotation of center \(\Omega\) and of angle \(\theta\) if and only if
A 2d rotation is defined by a point and an angle (in radians):
Point omega;
Real theta;
Rotation2d r(_center=omega, _angle=theta);
Important
The default angle is 0.0. The default center is the 3d zero point.
3d rotations#
Point B is the image of point A by the 3d rotation of axis \(\left(\Omega, \vec{d}\right)\) and of angle \(\theta\) (in radians) if and only if
where \(\displaystyle \vec{n}=\dfrac{\vec{u}}{||\vec{u}||}\) (the unitary direction).
The direction can be defined by an STL vector or by its components:
Point omega;
Vector<Real> d;
Real dx, dy, dz;
Real theta;
Rotation3d r1(_center=omega, _direction=d, _angle=theta), r2(_center=omega, _direction={dx, dy, dz}, _angle=theta);
Important
The default angle is 0.0. The default center and the default direction vector are the 3d zero point.
Scalings and homotheties#
Point B is the image of point A by the scaling of center \(\Omega\) and of factors \(k_x\), \(k_y\) and \(k_z\) if and only if
Point omega(1.,2.,3.);
Real kx, ky, kz;
Scaling s(_center=omega, _scale={kx, ky, kz});
When \(k_x=k_y=k_z=k\) are identical, this is a homothety:
Point omega(1.,2.,3.);
Real k;
Homothety h(_center=omega, _scale=k);
Important
The default factor is 1. The default center is the 3d zero vector.
Point reflections#
Point B is the image of point A by the point reflection of center \(\Omega\) if and only if
It is a homothety of factor -1 and same center.
Point omega(1.,2.,3.);
PointReflection h(_center=omega); // omega can still be omitted, as for homothety
2d reflections#
Point B is the image of point A by the 2d reflection of axis \(\left(\Omega,\vec{d}\right)\) if and only if
where \(H\) is the orthogonal projection of \(A\) on \(\left(\Omega,\vec{d}\right)\)
Point omega(1.,2.,3.);
Vector<Real> d(1.,0.,0.);
Real dx=1., dy=0.;
Reflection2d r1(_center=omega, _direction=d), r2(_center=omega, _direction={dx, dy});
Important
The default direction vector and the default center are the 2d zero vector.
3d reflections#
Point B is the image of point A by the 3d reflection of plane \(\left[\Omega,\vec{n}\right]\) if and only if
where \(H\) is the orthogonal projection of \(A\) on \(\left[\Omega,\vec{n}\right]\).
Point omega(1.,2.,3.);
Vector<Real> n;
Real nx, ny, nz;
Reflection3d r1(_center=omega, _normal=n), r2(_center=omega, _normal={nx, ny, nz});
Important
The default normal vector and the default center is the 3d zero vector.
General linear transformations#
Any linear transformation can be set from a matrix and a vector (\(x\rightarrow \mathbb{A}x+b\)) using the following Transformation constructors:
Transformation(const Matrix<Real>& A, const Vector<Real>& b = Vector<Real>(3,0.));
Transformation(Real a11, Real a12, Real a13, Real a21,Real a22, Real a23,
Real a31, Real a32, Real a33, Real b1=0, Real b2=0, Real b3=0);
Note
The matrix representation of a transformation can be accessed using the member functions mat and vec. Matrix representations are also available for canonical geometries.
Composition of transformations#
To define a composition of transformations, use the operator * between canonical transformations, as in the following example:
Rotation2d r1(Point(0.,0.), 120.);
Reflection2d r2(Point(1.,-1.), 1.,2.5, -3.);
Translation t1(-1.,4.);
Homothety h (Point(-1.,0.), -3.2);
Transformation t = r1*h*r2*t1;
Composition * has to be understood as usual composition operator \(\circ\) : \(t(P)=r1(h(r2(t1(P))))\).
Note
The matrix representation (mat and vec member functions) is available for composition of transformations.
Applying transformations#
How to apply a transformation ?#
The general syntax to apply a transformation on a Point is to define the transformation object and to call the apply routine :
Point a(3.,2.);
Translation t(_direction={1.,0.});
Point b=t.apply(a);
It is more convenient to use one of the available shortcuts. 2 possibilities:
-
You want to modify the point you are computing transformation:
Point a(3.,2.); a.translate(_direction={1.,0.});
-
You want to generate a new point:
Point a(3.,2.); Point b=translate(a, _direction={1.,0.});
Here is the full list of shortcuts :
translateto apply a translationrotate2dto apply a 2D rotationrotate3dto apply a 3D rotationhomothetizeto apply a homothetypointReflectto apply a point reflectionreflect2dto apply a 2D reflectionreflect3dto apply a 3D reflection
Important
A 2D rotation or a 2D reflection cannot be used for geometries defined by 3D points!