ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
axis_rotation.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s).
12#include "detray/definitions/algebra.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
14#include "detray/definitions/math.hpp"
15
16namespace detray {
17
20template <concepts::algebra algebra_t>
22 public:
24 using algebra_type = algebra_t;
30 template <std::size_t ROWS, std::size_t COLS>
32
37 DETRAY_HOST_DEVICE
38 axis_rotation(const vector3_type& axis, const scalar_type theta) {
39 // normalize the axis
40 const vector3_type U = vector::normalize(axis);
41
42 scalar_type cos_theta{math::cos(theta)};
43
44 auto I = matrix::identity<matrix_type<3, 3>>();
45 matrix_type<3, 3> axis_cross = matrix::cross_matrix(U);
46 matrix_type<3, 3> axis_outer = matrix::outer_product(U, U);
47
48 R = cos_theta * I + math::sin(theta) * axis_cross +
49 (1.f - cos_theta) * axis_outer;
50 }
51
54 template <typename vector3_t>
57 DETRAY_HOST_DEVICE vector3_t operator()(const vector3_t& v) const {
58 return R * v;
59 }
60
61 private:
63 matrix_type<3, 3> R{matrix::identity<matrix_type<3, 3>>()};
64};
65
68template <concepts::algebra algebra_t>
70 public:
72 using algebra_type = algebra_t;
77
79 vector3_type x{1.0f, 0.f, 0.f};
81 vector3_type z{0.f, 0.f, 1.f};
88
90 DETRAY_HOST_DEVICE std::pair<vector3_type, vector3_type> operator()() const {
91 // alpha around z axis
92 axis_rotation<algebra_t> axis_rot_alpha(z, alpha);
93 auto new_x = axis_rot_alpha(x);
94
95 // beta around x' axis
96 axis_rotation<algebra_t> axis_rot_beta(new_x, beta);
97 const auto new_z = axis_rot_beta(z);
98
99 axis_rotation<algebra_t> axis_rot_gamma(new_z, gamma);
100 new_x = axis_rot_gamma(new_x);
101
102 return std::make_pair(new_x, new_z);
103 }
104
108 DETRAY_HOST_DEVICE vector3_type operator()(const vector3_type& v0) const {
109 // alpha around z axis
110 axis_rotation<algebra_t> axis_rot_alpha(z, alpha);
111 const auto new_x = axis_rot_alpha(x);
112 const auto v1 = axis_rot_alpha(v0);
113
114 // beta around x' axis
115 axis_rotation<algebra_t> axis_rot_beta(new_x, beta);
116 const auto new_z = axis_rot_beta(z);
117 const auto v2 = axis_rot_beta(v1);
118
119 // gamma around z' axis
120 axis_rotation<algebra_t> axis_rot_gamma(new_z, gamma);
121 const auto v3 = axis_rot_gamma(v2);
122
123 return v3;
124 }
125};
126
127} // namespace detray
Definition concepts.hpp:98
Definition concepts.hpp:65
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
get_vector3D_t< A, T > dvector3D
Three-dimensional vector type for algebra A and value type T.
Definition algebra.hpp:80
get_matrix_t< A, R, C, T > dmatrix
R by C matrix type for algebra A and value type T.
Definition algebra.hpp:88
Helper struct to rotate a vector around a given axis and angle counterclockwisely.
Definition axis_rotation.hpp:21
dscalar< algebra_t > scalar_type
Scalar type used for the rotation angle and matrix entries.
Definition axis_rotation.hpp:26
algebra_t algebra_type
Algebra backend used for the rotation.
Definition axis_rotation.hpp:24
dmatrix< algebra_t, ROWS, COLS > matrix_type
Matrix type used to represent the rotation.
Definition axis_rotation.hpp:31
axis_rotation(const vector3_type &axis, const scalar_type theta)
Constructor for axis rotation.
Definition axis_rotation.hpp:38
dvector3D< algebra_t > vector3_type
Three-dimensional vector type rotated by this helper.
Definition axis_rotation.hpp:28
Helper struct to perform an euler rotation for a given vector All rotation operations are countercloc...
Definition axis_rotation.hpp:69
algebra_t algebra_type
Algebra backend used for the rotations.
Definition axis_rotation.hpp:72
scalar_type beta
Second rotation angle, about the rotated x axis.
Definition axis_rotation.hpp:85
dscalar< algebra_t > scalar_type
Scalar type used for the Euler angles.
Definition axis_rotation.hpp:74
scalar_type gamma
Third rotation angle, about the twice-rotated z axis.
Definition axis_rotation.hpp:87
vector3_type x
Following the z-x-z convention.
Definition axis_rotation.hpp:79
std::pair< vector3_type, vector3_type > operator()() const
Definition axis_rotation.hpp:90
vector3_type z
Initial z axis used to construct the rotated frame.
Definition axis_rotation.hpp:81
scalar_type alpha
First rotation angle, about the initial z axis.
Definition axis_rotation.hpp:83
vector3_type operator()(const vector3_type &v0) const
Apply the z-x-z Euler rotations to a vector.
Definition axis_rotation.hpp:108
dvector3D< algebra_t > vector3_type
Three-dimensional vector type used for the axes and input.
Definition axis_rotation.hpp:76