Loading...
Searching...
No Matches
transform.h
Go to the documentation of this file.
1#ifndef _BBM_TRANSFORM_H_
2#define _BBM_TRANSFORM_H_
3
4#include "core/vec.h"
5#include "core/mat.h"
6
7/***********************************************************************/
8/*! \file transform.h
9 \brief Basic matrix transformations
10************************************************************************/
11
12namespace bbm {
13
14 /*******************************************************************/
15 /*! \brief Rotation around the X-axis
16
17 \param angle = rotation angle
18 ********************************************************************/
19 template<typename T>
20 mat3d<std::decay_t<T>> rotationX(const vec2d<T>& cossin)
21 {
22 using matrix_t = mat3d<std::decay_t<T>>;
23 matrix_t result( vec3d<T>(1,0,0),
24 vec3d<T>(0, cossin[0], cossin[1]),
25 vec3d<T>(0, -cossin[1], cossin[0]) );
26 return result;
27 }
28
29 /*******************************************************************/
30 /*! \brief Rotation around the X-axis
31
32 \param angle = rotation angle
33 ********************************************************************/
34 template<typename T>
36 {
37 auto cossin = bbm::cossin(angle);
38 return rotationX(cossin);
39 }
40
41 /*******************************************************************/
42 /*! \brief Rotation around the Y-axis
43
44 \param angle = rotation angle
45 ********************************************************************/
46 template<typename T>
47 mat3d<std::decay_t<T>> rotationY(const vec2d<T>& cossin)
48 {
49 using matrix_t = mat3d<std::decay_t<T>>;
50 matrix_t result( vec3d<T>(cossin[0], 0, -cossin[1]),
51 vec3d<T>(0,1,0),
52 vec3d<T>(cossin[1], 0, cossin[0]) );
53 return result;
54 }
55
56 /*******************************************************************/
57 /*! \brief Rotation around the Y-axis
58
59 \param angle = rotation angle
60 ********************************************************************/
61 template<typename T>
63 {
64 auto cossin = bbm::cossin(angle);
65 return rotationY(cossin);
66 }
67
68 /*******************************************************************/
69 /*! \brief Rotation around the Z-axis
70
71 \param angle = rotation angle
72 ********************************************************************/
73 template<typename T>
74 mat3d<std::decay_t<T>> rotationZ(const vec2d<T>& cossin)
75 {
76 using matrix_t = mat3d<std::decay_t<T>>;
77 matrix_t result( vec3d<T>(cossin[0], cossin[1], 0),
78 vec3d<T>(-cossin[1], cossin[0], 0),
79 vec3d<T>(0,0,1) );
80 return result;
81 }
82
83 /*******************************************************************/
84 /*! \brief Rotation around the Z-axis
85
86 \param angle = rotation angle
87 ********************************************************************/
88 template<typename T>
90 {
91 auto cossin = bbm::cossin(angle);
92 return rotationZ(cossin);
93 }
94
95 /********************************************************************/
96 /*! \brief 2D rotation matrix
97
98 \param cossin = (cos, sin)
99 ********************************************************************/
100 template<typename T>
101 inline mat2d<std::decay_t<T>> rotation2d(const vec2d<T>& cossin)
102 {
103 using matrix_t = mat2d<std::decay_t<T>>;
104 matrix_t result( cossin, vec2d<T>(-cossin[1], cossin[0]) );
105 return result;
106 }
107
108 /********************************************************************/
109 /*! \brief 2D rotation matrix
110
111 \param angle = rotation angle
112 ********************************************************************/
113 template<typename T>
115 {
116 auto cossin = bbm::cossin(angle);
117 return rotation2d(cossin);
118 }
119
120} // end bbm namespace
121
122#endif /* _BBM_TRANSFORM_H_ */
Defines additional helper methods for vectors.
Definition: aggregatebsdf.h:29
mat3d< std::decay_t< T > > rotationY(const vec2d< T > &cossin)
Rotation around the Y-axis.
Definition: transform.h:47
mat3d< std::decay_t< T > > rotationZ(const vec2d< T > &cossin)
Rotation around the Z-axis.
Definition: transform.h:74
mat3d< std::decay_t< T > > rotationX(const vec2d< T > &cossin)
Rotation around the X-axis.
Definition: transform.h:20
bbm::detail::mat< vec3d< T >, 3 > mat3d
3D matrix
Definition: mat.h:178
mat2d< std::decay_t< T > > rotation2d(const vec2d< T > &cossin)
2D rotation matrix
Definition: transform.h:101
bbm::detail::mat< vec2d< T >, 2 > mat2d
2D matrix
Definition: mat.h:174