21 template <
class T,
int Dim>
24 template <
class T,
int Dim>
62 template <
class T,
int Dim>
71 point2 = base + direction*length;
89 template <
class T,
int Dim>
108 template <
class T,
int Dim>
115 scalar =
Dot(normal, base);
117 Hyperplane(
const VectorT& normal, T scalar) : normal(normal), scalar(scalar) {
121 static_assert(Dim == 2,
"Plane dimension must be two, which is a line.");
123 scalar =
Dot(normal, line.
Base());
126 const VectorT&
Normal()
const {
return normal; }
129 template <
bool Packed>
131 return Dot(point, normal) - scalar;
139 template <
class T,
int Dim>
141 static_assert(Dim == 2,
"Line dimension must be two, since it a plane in 2 dimensional space.");
148 base = { a*d / div, b*d / div };
168 template <
class T,
class U>
173 template <
class T,
class U>
180 template <
class T,
int Dim>
197 template <
class T,
int Dim>
208 template <
class T,
int Dim>
217 param = intersection.LineParameter() / line.
Length();
229 template <
class T,
int Dim>
239 template <
class T,
int Dim>
259 A_inv_t = 1 | plane.
Normal();
263 T x_t =
Dot(A_inv_t, b);
279 param2 = intersection.LineParameter();
280 param1 = std::isinf(param2) ? std::numeric_limits<T>::infinity() :
Length(intersection.Point() - l1.
Base());
308 if (intersection.Intersecting()) {
309 param1 = intersection.LineParameter1() / l1.
Length();
310 param2 = intersection.LineParameter2() / l2.
Length();
313 param1 = param2 = std::numeric_limits<T>::infinity();
337 if (inter.Intersecting() && inter.LineParameter1() < line1.
Length()) {
338 param1 = inter.LineParameter1();
339 param2 = inter.LineParameter2();
342 param1 = param2 = std::numeric_limits<T>::infinity();
380 VectorT
Point()
const {
return point; }
383 U Interpolate(
const U& a,
const U& b,
const U& c)
const;
397 constexpr T EPSILON = T(0.00000001);
405 if (std::abs(a) < EPSILON) {
406 intersecting =
false;
414 if (u < T(0) || u > T(1)) {
415 intersecting =
false;
422 if (v < 0.0 || u + v > 1.0) {
423 intersecting =
false;
427 t = f *
Dot(edge2, q);
428 intersecting = t > EPSILON;
439 return u*b + v*c + w*a;
443 template <
class T,
int Dim,
int Order>
445 static_assert(Order >= 1,
"Bezier curve must have order n>=1.");
450 return EvalInterpolRecurse(t);
454 VectorT EvalInterpolRecurse(T t)
const;
457 std::array<VectorT, Order+1>
p;
461 template <
class T,
int Dim,
int Order>
463 std::array<VectorT, Order+1> reduction = p;
467 for (
int i=Order; i>=1; --i) {
468 for (
int j=1; j<=i; ++j) {
469 reduction[j-1] = u*reduction[j-1] + t*reduction[j];
T InterpolParameter1() const
Definition: Geometry.hpp:319
Vector< T, 2 > Point() const
Definition: Geometry.hpp:318
bool Intersecting() const
Definition: Geometry.hpp:346
T LineParameter1() const
Definition: Geometry.hpp:321
VectorT operator()(T t) const
Definition: Geometry.hpp:449
Intersection(const LineSegment< T, 2 > &l1, const LineSegment< T, 2 > &l2)
Definition: Geometry.hpp:304
bool Intersecting() const
Definition: Geometry.hpp:189
T Distance(const Vector< T, Dim, Packed > &point)
Definition: Geometry.hpp:130
VectorT base
Definition: Geometry.hpp:57
Intersection(const LineT &line, const PlaneT &plane)
Definition: Geometry.hpp:202
Definition: Geometry.hpp:22
Vector< T, 3, false > c
Definition: Geometry.hpp:159
mathter::Line< T, Dim > Line() const
Definition: Geometry.hpp:81
Hyperplane(const VectorT &base, const VectorT &normal)
Definition: Geometry.hpp:113
VectorT Start() const
Definition: Geometry.hpp:77
bool Intersecting() const
Definition: Geometry.hpp:283
Definition: Geometry.hpp:169
VectorT Point() const
Definition: Geometry.hpp:221
T Length() const
Definition: Geometry.hpp:75
std::array< VectorT, Order+1 > p
Definition: Geometry.hpp:457
T LineParameter2() const
Definition: Geometry.hpp:350
Quaternion< T, Packed > Normalize(const Quaternion< T, Packed > &q)
Returns the unit quaternion of the same direction. Does not change this object.
Definition: QuaternionFunction.hpp:66
Definition: Geometry.hpp:63
Definition: Geometry.hpp:154
Vector< T, 2 > Point() const
Definition: Geometry.hpp:347
T LineParameter2() const
Definition: Geometry.hpp:368
bool IsIntersecting() const
Definition: Geometry.hpp:379
VectorT point2
Definition: Geometry.hpp:85
Intersection(const PlaneT &plane, const LineT &line)
Definition: Geometry.hpp:214
T Dot(const Vector< T, Dim, Packed > &lhs, const Vector< T, Dim, Packed > &rhs)
Calculates the scalar product (dot product) of the two arguments.
Definition: VectorFunction.hpp:111
static Line Through(const VectorT &point1, const VectorT &point2)
Constructs a line through both points.
Definition: Geometry.hpp:41
Definition: Geometry.hpp:25
LineSegment()
Definition: Geometry.hpp:66
T InterpolParameter2() const
Definition: Geometry.hpp:320
Intersection(const Line< T, 2 > &line1, const LineSegment< T, 2 > &line2)
Definition: Geometry.hpp:360
Intersection(const LineT &l1, const LineT &l2)
Definition: Geometry.hpp:276
Vector< T, 2 > Point() const
Definition: Geometry.hpp:286
T GetU() const
Definition: Geometry.hpp:386
VectorT direction
Definition: Geometry.hpp:57
T LineParameter2() const
Definition: Geometry.hpp:285
Definition: Approx.hpp:11
T GetV() const
Definition: Geometry.hpp:387
T LineParameter1() const
Definition: Geometry.hpp:366
T LineParameter1() const
Definition: Geometry.hpp:348
Definition: Geometry.hpp:90
Hyperplane(const VectorT &normal, T scalar)
Definition: Geometry.hpp:117
T InterpolParameter1() const
Definition: Geometry.hpp:349
auto Intersect(const T &t, const U &u)
Definition: Geometry.hpp:174
T LineParameter2() const
Definition: Geometry.hpp:322
Line(const VectorT &base, const VectorT &direction)
Construct a line through base in given direction .
Definition: Geometry.hpp:34
Hyperplane(const Line< T, 2 > &line)
Definition: Geometry.hpp:120
VectorT Interpol(T t) const
Definition: Geometry.hpp:79
VectorT Direction() const
Definition: Geometry.hpp:76
VectorT End() const
Definition: Geometry.hpp:78
Hyperplane()
Definition: Geometry.hpp:112
const VectorT & Normal() const
Definition: Geometry.hpp:126
LineSegment(const VectorT &base, const VectorT &direction, T length)
Definition: Geometry.hpp:69
bool Intersecting() const
Definition: Geometry.hpp:317
Vector< T, 3, false > a
Definition: Geometry.hpp:159
T InterpolParameter() const
Definition: Geometry.hpp:222
Triangle3D(const Vector< T, 3, false > &a, const Vector< T, 3, false > &b, const Vector< T, 3, false > &c)
Definition: Geometry.hpp:157
VectorT PointAt(T param) const
Returns the point at param distance from the base point along direction.
Definition: Geometry.hpp:55
VectorT Point() const
Definition: Geometry.hpp:190
Intersection(const Hyperplane< T, 2 > &p1, const Hyperplane< T, 2 > &p2)
Definition: Geometry.hpp:296
Line()=default
Does not zero-initialize members.
VectorT Base() const
Returns the base point or point1 as given in constructor.
Definition: Geometry.hpp:52
T Scalar() const
Definition: Geometry.hpp:127
bool Intersecting() const
Definition: Geometry.hpp:220
Vector< T, 3, false > b
Definition: Geometry.hpp:159
T LineParameter() const
Definition: Geometry.hpp:223
Intersection(const LineT &line, const PlaneT &plane)
Definition: Geometry.hpp:234
auto Cross(const Vector< T, Dim, Packed > &head, Args &&... args) -> Vector< T, Dim, Packed >
Returns the generalized cross-product in N dimensions.
Definition: VectorFunction.hpp:223
T LineParameter() const
Definition: Geometry.hpp:191
T GetT() const
Definition: Geometry.hpp:385
T InterpolParameter2() const
Definition: Geometry.hpp:367
Intersection(const LineSegment< T, 2 > &line1, const Line< T, 2 > &line2)
Definition: Geometry.hpp:335
mathter::Line< T, Dim > Line() const
Definition: Geometry.hpp:101
VectorT Point() const
Definition: Geometry.hpp:380
LineSegment(const VectorT &point1, const VectorT &point2)
Definition: Geometry.hpp:73
VectorT Direction() const
Return the signed direction of the line (as given in constructor).
Definition: Geometry.hpp:49
T Length(const Quaternion< T, Packed > &q)
Returns the absolute value of the quaternion.
Definition: QuaternionFunction.hpp:60
Definition: Geometry.hpp:444
Vector< T, Dim, Packed > SafeNormalize(const Vector< T, Dim, Packed > &v)
Makes a unit vector, but keeps direction. Leans towards (1,0,0...) for nullvectors, costs more.
Definition: VectorFunction.hpp:76
T LineParameter1() const
Definition: Geometry.hpp:284
bool IsNormalized(const Quaternion< T, Packed > &q)
Check if the quaternion is a unit quaternion, with some tolerance for floats.
Definition: QuaternionFunction.hpp:78