ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
unit_vectors.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/containers.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
15
16namespace detray {
17
21template <concepts::vector3D vector3_t>
31 DETRAY_HOST_DEVICE inline vector3_t make_curvilinear_unit_u(
32 const vector3_t& dir) {
33 vector3_t unit_u{0.f, 0.f, 0.f};
34 // explicit version of U = Z x T
35 unit_u[0] = -dir[1];
36 unit_u[1] = dir[0];
37
38 // if the absolute scale is tiny, the initial direction vector is
39 // aligned with the z-axis. the ZxT product is ill-defined since any
40 // vector in the x-y plane would be orthogonal to the direction. fix the
41 // U unit vector along the x-axis to avoid this numerical instability.
42 if (const auto scale = vector::norm(unit_u); scale < 1e-6f) {
43 unit_u[0] = 1;
44 unit_u[1] = 0;
45 } else {
46 unit_u = unit_u * (1.f / scale);
47 }
48
49 return unit_u;
50 }
51
69 const vector3_t& dir) {
71 uv[0] = make_curvilinear_unit_u(dir);
72 uv[1] = vector::normalize(vector::cross(dir, uv[0]));
73
74 return uv;
75 }
76};
77
78} // namespace detray
Detray include(s).
Definition array_operators.hpp:18
std::array< value_t, kDIM > darray
Fixed-size array container.
Definition containers.hpp:30
Build the curvilinear unit basis perpendicular to a three-dimensional direction.
Definition unit_vectors.hpp:22
darray< vector3_t, 2 > make_curvilinear_unit_vectors(const vector3_t &dir)
Construct the curvilinear unit vectors U and V for the given direction.
Definition unit_vectors.hpp:68
vector3_t make_curvilinear_unit_u(const vector3_t &dir)
Construct the first curvilinear unit vector U for the given direction.
Definition unit_vectors.hpp:31