33#include <NDEVR/BaseValues.h>
34#include <NDEVR/Vertex.h>
35#include <NDEVR/VectorFunctions.h>
50 template<u
int01 t_dims,
class t_type,
class t_vertex = Vertex<t_dims, t_type>>
54 constexpr RadialObject(t_type r = 0)
58 constexpr RadialObject(
const t_vertex&
center, t_type
radius)
73 constexpr RadialObject(
const t_vertex& vertex_a,
const t_vertex& vertex_b,
const t_vertex& vertex_c)
74 : m_center(
Constant<t_type>::Invalid)
75 , m_radius(
Constant<t_type>::Invalid)
77 static_assert(t_dims == 2,
"Radial Object given 3 points must be defined in 2 dimensions");
78 const t_vertex A = vertex_a;
79 const t_vertex B = vertex_b;
80 const t_vertex C = vertex_c;
82 const t_type D = 2 * (A[X] * (B[Y] - C[Y]) + B[X] * (C[Y] - A[Y]) + C[X] * (A[Y] - B[Y]));
86 const t_type A_sq = A[X] * A[X] + A[Y] * A[Y];
87 const t_type B_sq = B[X] * B[X] + B[Y] * B[Y];
88 const t_type C_sq = C[X] * C[X] + C[Y] * C[Y];
90 const t_type Ux = (A_sq * (B[Y] - C[Y]) + B_sq * (C[Y] - A[Y]) + C_sq * (A[Y] - B[Y])) / D;
91 const t_type Uy = (A_sq * (C[X] - B[X]) + B_sq * (A[X] - C[X]) + C_sq * (B[X] - A[X])) / D;
93 m_center = t_vertex(Ux, Uy);
94 m_radius = distance<t_type>(m_center, vertex_a);
110 template<
bool t_allow_bounds = true>
111 constexpr bool contains(
const t_vertex& vector)
const
114 return distanceSquared(m_center, vector) <= m_radius * m_radius;
116 return distanceSquared(m_center, vector) < m_radius * m_radius;
129 constexpr t_type
radius()
const {
return m_radius;}
142 template<u
int01 t_new_dims,
class t_new_type,
class t_new_vertex = Vertex<t_new_dims, t_new_type>>
143 constexpr RadialObject<t_new_dims, t_new_type>
as()
const
158 [[nodiscard]]
constexpr const t_vertex&
center()
const {
return m_center;}
162 return m_radius == rad.m_radius && (m_center == rad.m_center);
164 bool operator!=(
const RadialObject& rad)
const
166 return m_radius != rad.m_radius || m_center != rad.m_center;
175 template<u
int01 t_dims,
class t_type,
class t_vector>
178 constexpr const static RadialObject<t_dims, t_type, t_vector> Invalid{ Constant<t_vector>::Invalid, Constant<t_type>::Invalid };
179 constexpr const static RadialObject<t_dims, t_type, t_vector> Min{ t_vector(0), 0 };
180 constexpr const static RadialObject<t_dims, t_type, t_vector> Max{ t_vector(0), Constant<t_type>::Max};
187 template<u
int01 t_dims,
class t_type,
class t_vertex = Vertex<t_dims, t_type>>
191 constexpr BiRadialObject(t_type r = 0)
195 constexpr BiRadialObject(
const t_vertex& p1,
const t_vertex& p2, t_type
radius)
196 : m_axis_major(p1, p2)
201 template<
class t_matrix_type = fltp08>
202 static BiRadialObject<t_dims, t_type, t_vertex> fromCircleTransform(
const Matrix<t_matrix_type>& mat)
204 BiRadialObject<t_dims, t_type, t_vertex> object;
206 Ray<3, fltp08> direction = mat * Ray<3, fltp08>(0.5, 0, 0);
208 object.m_axis_major[A] =
center + direction;
209 object.m_axis_major[B] =
center - direction;
213 object.m_radius =
getMin(scale[X], scale[Y]);
230 constexpr bool contains(
const t_vertex& vector)
const
232 fltp08 total_distance = distance<fltp08>(m_axis_major[A], vector) + distance<fltp08>(m_axis_major[B], vector);
233 return m_radius > total_distance - distance<fltp08>(m_axis_major[A], m_axis_major[B]);
246 constexpr t_type
radius()
const {
return m_radius; }
259 template<u
int01 t_new_dims,
class t_new_type>
260 constexpr BiRadialObject<t_new_dims, t_new_type>
as()
const
275 constexpr t_vertex
center()
const {
return t_vertex((m_axis_major[A] + m_axis_major[B]) /
cast<t_type>(2)); }
276 constexpr const t_vertex& axisPoint(
uint01 vertex)
const
278 return m_axis_major[vertex];
281 template<
class t_ratio_type = fltp08>
282 t_ratio_type minorToMajorRatio()
const
284 const t_ratio_type axis_distance = distance<t_ratio_type>(m_axis_major[A], m_axis_major[B]);
287 template<
class t_matrix_type = fltp08>
288 Matrix<t_matrix_type> fromCircleTransform()
const
290 Matrix<t_matrix_type> mat = Matrix<t_matrix_type>::ScalerMatrix(m_radius);
291 if (m_axis_major[B] - m_axis_major[A] == t_vertex(0))
293 Vector<t_dims, t_type> axis = (m_axis_major[B] - m_axis_major[A]).
template normalized<t_matrix_type>();
295 mat = mat.scale(axis, scale);
300 Vector<2, t_vertex> m_axis_major;
constexpr bool contains(const t_vertex &vector) const
constexpr t_type radius() const
constexpr t_vertex center() const
constexpr BiRadialObject< t_new_dims, t_new_type > as() const
Templated logic for doing matrix multiplication.
constexpr RadialObject< t_new_dims, t_new_type > as() const
constexpr const t_vertex & center() const
constexpr t_type radius() const
constexpr bool contains(const t_vertex &vector) const
constexpr RadialObject(const t_vertex &vertex_a, const t_vertex &vertex_b, const t_vertex &vertex_c)
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
A point in N-dimensional space, used primarily for spatial location information.
The primary namespace for the NDEVR SDK.
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...