22#include <external/Eigen/Dense>
36 if constexpr (
dim != 2 &&
dim != 3)
37 throw std::invalid_argument(
"GeometryOps::polar_to_cartesian(): `dim` must be 2 or 3.");
40 points_out.row(0) = points.row(0).array() * Eigen::cos(points.row(1).array());
41 points_out.row(1) = points.row(0).array() * Eigen::sin(points.row(1).array());
44 points_out.row(0).array() *= Eigen::sin(points.row(2).array());
45 points_out.row(1).array() *= Eigen::sin(points.row(2).array());
46 points_out.row(2) = points.row(0).array() * Eigen::cos(points.row(2).array());
58 if constexpr (
dim != 2 &&
dim != 3)
59 throw std::invalid_argument(
"GeometryOps::cartesian_to_polar_field(): `dim` must be 2 or 3.");
71 if constexpr (
dim == 3)
102template <u
int8_t dim>
113template <u
int8_t dim>
119 if constexpr (
dim != 2 &&
dim != 3)
120 throw std::invalid_argument(
"GeometryOps::angle_between_vectors(): `dim` must be 2 or 3.");
122 if (
v1.cols() !=
v2.cols())
123 throw std::invalid_argument(
124 "angle_between_vectors(): number of vectors in set v1 does not equal the number of vectors in set v2."
128 (
v1.cwiseProduct(
v2)).colwise().sum().array() /
129 v1.colwise().norm().array() /
130 v2.colwise().norm().array()
135template <u
int8_t dim>
141 if constexpr (
dim != 2 &&
dim != 3)
142 throw std::invalid_argument(
"GeometryOps::directed_angle_between_vectors(): `dim` must be 2 or 3.");
144 if (
v1.cols() !=
v2.cols())
145 throw std::invalid_argument(
146 "directed_angle_between_vectors(): number of vectors in set v1 does not equal the number of vectors in set v2."
151 if constexpr (
dim == 2)
152 det.noalias() =
v1.row(0) *
v2.row(1).asDiagonal() -
v2.row(0) *
v1.row(1).asDiagonal();
153 else if constexpr (
dim == 3)
161 Float tol = std::max(
162 v1.colwise().norm().maxCoeff(),
v2.colwise().norm().maxCoeff()
163 ) * GEOMETRY_DEFAULT_TOL;
172template <u
int8_t dim>
200template <u
int8_t dim>
214 idx1.setConstant(10);
215 idx2.setConstant(10);
234template <u
int8_t dim>
250template <u
int8_t dim>
264template <u
int8_t dim>
282template <u
int8_t dim>
289 if (std::abs(
edge1.unit_vec().dot(
edge2.unit_vec()) - 1.0) <= tol)
291 if (std::abs(
edge1.unit_vec().dot(
edge2.unit_vec()) + 1.0) <= tol)
297template <u
int8_t dim>
304 if (
edge1.unit_vec().dot(
edge2.unit_vec()) <= tol)
310template <u
int8_t dim>
322 throw std::invalid_argument(
"GeometryOps::point_in_polygon(): `polygon` must have at least three vertices.");
327 if constexpr (
dim == 1)
328 throw std::invalid_argument(
"GeometryOps::point_in_polygon(): `dim` must be 2 or 3.");
330 else if constexpr (
dim == 3)
354 else if constexpr (
dim == 2)
static EigMatNX< Complex, dim > cartesian_to_polar_field(ConstEigRef< EigMatNX< Float, dim > > points, ConstEigRef< EigMatNX< Complex, dim > > field)
Transforms a vector field in Cartesian space to polar (2D) or spherical (3D) space.
static EigRowVec< Float > directed_angle_between_vectors(ConstEigRef< EigMatNX< Float, dim > > v1, ConstEigRef< EigMatNX< Float, dim > > v2)
Returns the directional angles between pairs of vectors in a right-hand system where counter-clockwis...
static bool point_in_polygon(ConstEigRef< EigColVecN< Float, dim > > &point, ConstEigRef< EigMatNX< Float, dim > > &polygon, const Float tol=GEOMETRY_DEFAULT_TOL)
Checks if a point is inside a polygon using ray casting.
static EigRowVec< Float > angle_between_vectors(ConstEigRef< EigMatNX< Float, dim > > v1, ConstEigRef< EigMatNX< Float, dim > > v2)
Returns the angles between pairs of vectors in radians.
static bool check_coplanar_triangles(const Triangle< 3 > &triangle1, const Triangle< 3 > &triangle2, const Float tol=GEOMETRY_DEFAULT_TOL)
Checks if two triangles are coplanar.
static uint8_t common_vertices(const Triangle< dim > &triangle1, const Triangle< dim > &triangle2, const Float tol=GEOMETRY_DEFAULT_TOL)
Returns the number of vertices common or coinciding between two Triangle objects.
static int8_t check_parallel_triangles(const Triangle< 3 > &triangle1, const Triangle< 3 > &triangle2, const Float tol=GEOMETRY_DEFAULT_TOL)
Checks if the normal vectors of two triangles are (anti-)parallel.
static EigMatNX< Float, dim > transform_coordinate_system(ConstEigRef< EigMatNX< Float, dim > > v_in, ConstEigRef< EigColVecN< Float, dim > > new_origin, ConstEigRef< EigMatMN< Float, dim, dim > > new_uvw)
Transforms the given coordinates to a new coordinate system defined by a new origin and orthogonal un...
static EigMatNX< Float, dim > polar_to_cartesian(ConstEigRef< EigMatNX< Float, dim > > points)
Transforms polar (2D) or spherical (3D) coordinates to Cartesian.
static bool check_perpendicular_triangles(const Triangle< 3 > &triangle1, const Triangle< 3 > &triangle2, const Float tol=GEOMETRY_DEFAULT_TOL)
Checks if the normal vectors of two triangles are perpendicular.
static bool check_perpendicular_edges(const Edge< dim > &edge1, const Edge< dim > &edge2, const Float tol=GEOMETRY_DEFAULT_TOL)
Checks if two edges are perpendicular.
static int8_t check_parallel_edges(const Edge< dim > &edge1, const Edge< dim > &edge2, const Float tol=GEOMETRY_DEFAULT_TOL)
Checks if two edges are (anti-)parallel.
Eigen::Ref< EigObj > EigRef
Writable reference to an Eigen object.
const Eigen::Ref< const EigObj > ConstEigRef
Read-only reference to an Eigen object.
Eigen::Matrix< T, 1, Eigen::Dynamic > EigRowVec
Dynamic-size row vector containing type T.
double Float
Floating point number.
Eigen::Matrix< T, N, 1 > EigColVecN
Fixed-size column vector of size N containing type T.
Eigen::Matrix< T, N, Eigen::Dynamic > EigMatNX
Fixed-height matrix with N rows containing type T.
std::size_t Index
Unsigned integer type for indices and container sizes.
Primary namespace for the OpenBEM library.