ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
cylindrical_transformation_parameters.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <cmath>
23#include <limits>
24#include <stdexcept>
25#include <string>
26
27#include "utils/Vector.hpp"
29
30namespace Utils {
31
32/**
33 * @brief A class to hold and validate parameters for a cylindrical coordinate
34 * transformations.
35 */
37public:
39 /**
40 * @brief Main constructor.
41 *
42 * @param center The origin of the cylindrical coordinates.
43 * @param axis The "z"-axis. Must be normalized.
44 * @param orientation The axis along which phi = 0. Must be normalized and
45 * orthogonal to axis.
46 */
48 Utils::Vector3d const &axis,
50 : m_center(center), m_axis(axis), m_orientation(orientation) {
51 validate();
52 }
53 /**
54 * @brief if you only provide center and axis, an orientation will be
55 * generated automatically such that it is orthogonal to axis
56 */
61
62 Utils::Vector3d center() const { return m_center; }
63 Utils::Vector3d axis() const { return m_axis; }
64 Utils::Vector3d orientation() const { return m_orientation; }
65
66private:
67 void validate() const {
68 auto constexpr eps = 10. * std::numeric_limits<double>::epsilon();
69 if (std::fabs(m_orientation * m_axis) > eps) {
70 throw std::runtime_error(
71 "CylindricalTransformationParameters: Axis and orientation must be "
72 "orthogonal. Scalar product is " +
73 std::to_string(m_orientation * m_axis));
74 }
75 if (std::fabs(m_axis.norm() - 1.) > eps) {
76 throw std::runtime_error("CylindricalTransformationParameters: Axis must "
77 "be normalized. Norm is " +
78 std::to_string(m_axis.norm()));
79 }
80 if (std::fabs(m_orientation.norm() - 1.) > eps) {
81 throw std::runtime_error("CylindricalTransformationParameters: "
82 "orientation must be normalized. Norm is " +
83 std::to_string(m_orientation.norm()));
84 }
85 }
86
87 Utils::Vector3d const m_center{};
88 Utils::Vector3d const m_axis{0., 0., 1.};
89 Utils::Vector3d const m_orientation{1., 0., 0.};
90};
91
92} // namespace Utils
Vector implementation and trait types for boost qvm interoperability.
A class to hold and validate parameters for a cylindrical coordinate transformations.
CylindricalTransformationParameters(Utils::Vector3d const &center, Utils::Vector3d const &axis)
if you only provide center and axis, an orientation will be generated automatically such that it is o...
CylindricalTransformationParameters(Utils::Vector3d const &center, Utils::Vector3d const &axis, Utils::Vector3d const &orientation)
Main constructor.
T norm() const
Definition Vector.hpp:168
Vector< T, N > calc_orthonormal_vector(Vector< T, N > const &vec)
Return a vector that is orthonormal to vec.