23#ifndef VCL_ALGORITHMS_CORE_TRANSFORM_H
24#define VCL_ALGORITHMS_CORE_TRANSFORM_H
26#include <vclib/space/core.h>
47template<MatrixConcept MatrixType, Po
int3Concept Po
intType,
typename ScalarType>
57 matrix(0, 0) = axis[0] * axis[0] *
q + c;
58 matrix(0, 1) = axis[0] * axis[1] *
q - axis[2] * s;
59 matrix(0, 2) = axis[0] * axis[2] *
q + axis[1] * s;
60 matrix(1, 0) = axis[1] * axis[0] *
q + axis[2] * s;
61 matrix(1, 1) = axis[1] * axis[1] *
q + c;
62 matrix(1, 2) = axis[1] * axis[2] *
q - axis[0] * s;
63 matrix(2, 0) = axis[2] * axis[0] *
q - axis[1] * s;
64 matrix(2, 1) = axis[2] * axis[1] *
q + axis[0] * s;
65 matrix(2, 2) = axis[2] * axis[2] *
q + c;
83template<MatrixConcept MatrixType, Po
int3Concept Po
intType,
typename ScalarType>
107template<MatrixConcept MatrixType, Po
int3Concept Po
intType>
114 matrix.block(0, 0, 3, 3).setIdentity();
118 auto angle = std::acos(
123template<MatrixConcept MatrixType, Po
int3Concept Po
intType>
124void setTransformMatrixTranslation(
126 const PointType& translation)
128 matrix(0, 3) = translation[0];
129 matrix(1, 3) = translation[1];
130 matrix(2, 3) = translation[2];
133template<MatrixConcept MatrixType,
typename ScalarType>
134void setTransformMatrixScale(MatrixType& matrix,
const ScalarType& scale)
136 matrix(0, 0) = scale;
137 matrix(1, 1) = scale;
138 matrix(2, 2) = scale;
142template<MatrixConcept MatrixType, Po
int3Concept Po
intType>
143void setTransformMatrixScale(MatrixType& matrix,
const PointType& scale)
145 matrix(0, 0) = scale[0];
146 matrix(1, 1) = scale[1];
147 matrix(2, 2) = scale[2];
166template<MatrixConcept MatrixType, Po
int3Concept Po
intType,
typename ScalarType>
191template<MatrixConcept MatrixType, Po
int3Concept Po
intType,
typename ScalarType>
212template<MatrixConcept MatrixType, Po
int3Concept Po
intType>
237template<Matrix33Or44Concept MatrixType>
240 using ScalarType =
typename MatrixType::Scalar;
241 ScalarType
scaleX = std::sqrt(
244 ScalarType
scaleY = std::sqrt(
247 ScalarType
scaleZ = std::sqrt(
250 for (
int i = 0;
i < 3; ++
i) {
273template<Matrix33Or44Concept MatrixType>
281template<Po
int3Concept Po
intType, Matrix33Concept MatrixType>
282PointType multiplyNormalByMatrix(
283 const PointType& normal,
287 using ScalarType =
typename PointType::Scalar;
291 return mat.template cast<ScalarType>() * normal;
294template<Po
int3Concept Po
intType, Matrix44Concept MatrixType>
295PointType multiplyNormalByMatrix(
296 const PointType& normal,
300 using ScalarType =
typename PointType::Scalar;
302 Matrix33<ScalarType> m33 =
303 mat.template cast<ScalarType>().block(0, 0, 3, 3);
310template<Range R, Matrix44Concept MatrixType>
311void multiplyPointsByMatrix(R&& points,
const MatrixType& mat)
312 requires Point3Concept<std::ranges::range_value_t<R>>
314 using PointType = std::ranges::range_value_t<R>;
315 using ScalarType = PointType::ScalarType;
317 Matrix44<ScalarType> m44 = mat.template cast<ScalarType>();
319 parallelFor(points, [&](
auto& point) {
324template<Range R, Matrix33Concept MatrixType>
325void multiplyNormalsByMatrix(
327 const MatrixType& mat,
329 requires Point3Concept<std::ranges::range_value_t<R>>
331 using PointType = std::ranges::range_value_t<R>;
332 using ScalarType = PointType::ScalarType;
334 Matrix33<ScalarType> m33 = mat.template cast<ScalarType>();
340 parallelFor(normals, [&](
auto& normal) {
341 normal = m33 * normal;
345template<Range R, Matrix44Concept MatrixType>
346void multiplyNormalsByMatrix(
348 const MatrixType& mat,
350 requires Point3Concept<std::ranges::range_value_t<R>>
352 using PointType = std::ranges::range_value_t<R>;
353 using ScalarType = PointType::ScalarType;
355 Matrix33<ScalarType> m33 =
356 mat.template cast<ScalarType>().block(0, 0, 3, 3);
A class representing a box in N-dimensional space.
Definition box.h:46
void removeScalingFromMatrixInPlace(MatrixType &matrix)
Removes the scaling factors from the matrix in place.
Definition transform.h:238
void setTransformMatrixRotation(MatrixType &matrix, PointType axis, const ScalarType &angleRad)
Given an 3D axis and an angle expressed in radiants, fills the given matrix with a transform matrix t...
Definition transform.h:48
MatrixType removeScalingFromMatrix(const MatrixType &matrix)
Returns a matrix with the scaling factors removed.
Definition transform.h:274
MatrixType rotationMatrixDeg(const PointType &axis, const ScalarType &angleDeg)
Given an 3D axis and an angle expressed in degrees, fills the given matrix with a transform matrix th...
Definition transform.h:192
void setTransformMatrixRotationDeg(MatrixType &matrix, PointType axis, const ScalarType &angleDeg)
Given an 3D axis and an angle expressed in degrees, fills the given matrix with a transform matrix th...
Definition transform.h:84
MatrixType rotationMatrix(const PointType &axis, const ScalarType &angleRad)
Given an 3D axis and an angle expressed in radiants, returns a transform matrix that represents the r...
Definition transform.h:167
Scalar toRad(const Scalar °)
Converts an angle in degrees to radians.
Definition math.h:81