11#ifndef JAU_MATH_GEOM_GEOM3F_HPP_
12#define JAU_MATH_GEOM_GEOM3F_HPP_
42 std::string
toString() const noexcept {
return "L[" +
p0.toString() +
", " +
p1.toString() +
"]"; }
54 const float determinant = (
p0.x -
p1.x ) * ( o.
p0.
y - o.
p1.
y) - (
p0.y -
p1.y ) * ( o.
p0.
x - o.
p1.
x );
55 if( 0 == determinant ) {
58 const float alpha =
p0.x *
p1.y -
p0.y *
p1.x;
60 const float xi = ((o.
p0.
x-o.
p1.
x)*alpha-(
p0.x-
p1.x)*beta)/determinant;
62 const float gamma0 = (xi -
p0.x) / (
p1.x -
p0.x);
63 const float gamma1 = (xi - o.
p0.
x) / (o.
p1.
x - o.
p0.
x);
64 if(gamma0 <= 0 || gamma0 >= 1 || gamma1 <= 0 || gamma1 >= 1) {
67 const float yi = ((o.
p0.
y-o.
p1.
y)*alpha-(
p0.y-
p1.y)*beta)/determinant;
82 const float determinant = (
p0.x -
p1.x ) * ( o.
p0.
y - o.
p1.
y) - (
p0.y -
p1.y ) * ( o.
p0.
x - o.
p1.
x );
83 if( 0 == determinant ) {
86 const float alpha =
p0.x *
p1.y -
p0.y *
p1.x;
88 const float xi = ((o.
p0.
x-o.
p1.
x)*alpha-(
p0.x-
p1.x)*beta)/determinant;
90 const float gamma0 = (xi -
p0.x) / (
p1.x -
p0.x);
91 const float gamma1 = (xi - o.
p0.
x) / (o.
p1.
x - o.
p0.
x);
92 if(gamma0 <= 0 || gamma0 >= 1 || gamma1 <= 0 || gamma1 >= 1) {
101 const Vec3f e = (box.high() - box.low()) * 0.5f;
102 const Vec3f aabb_center = (box.low() + box.high()) * 0.5f;
103 const Vec3f lseg_center =
p0 + d;
104 const Vec3f c = lseg_center - aabb_center;
105 Vec3f ad(std::abs(d.
x), std::abs(d.
y), std::abs(d.
z));
106 if (std::abs(c.
x) > e.
x + ad.
x)
108 if (std::abs(c.
y) > e.
y + ad.
y)
110 if (std::abs(c.
z) > e.
z + ad.
z)
112 if (std::abs(d.
y * c.
z - d.
z * c.
y) > e.
y * ad.
z + e.
z * ad.
y + std::numeric_limits<float>::epsilon()) {
115 if (std::abs(d.
z * c.
x - d.
x * c.
z) > e.
z * ad.
x + e.
x * ad.
z + std::numeric_limits<float>::epsilon()) {
118 if (std::abs(d.
x * c.
y - d.
y * c.
x) > e.
x * ad.
y + e.
y * ad.
x + std::numeric_limits<float>::epsilon()) {
127 Vec3f r(a); (r+=b)*=0.5f;
return r;
148 const float dotAC_AC = ac.
dot(ac);
149 const float dotAC_AB = ac.
dot(ab);
150 const float dotAB_AB = ab.
dot(ab);
153 const float invDenom = 1 / (dotAC_AC * dotAB_AB - dotAC_AB * dotAC_AB);
156 const float dotAC_AP1 = ac.
dot(ap);
157 const float dotAB_AP1 = ab.
dot(ap);
158 const float u = (dotAB_AB * dotAC_AP1 - dotAC_AB * dotAB_AP1) * invDenom;
159 const float v = (dotAC_AC * dotAB_AP1 - dotAC_AB * dotAC_AP1) * invDenom;
162 if ( (u >= 0) && (v >= 0) && (u + v < 1) ) {
169 const float dotAC_AP2 = ac.
dot(ap);
170 const float dotAB_AP2 = ab.
dot(ap);
171 const float u = (dotAB_AB * dotAC_AP2 - dotAC_AB * dotAB_AP2) * invDenom;
172 const float v = (dotAC_AC * dotAB_AP2 - dotAC_AB * dotAC_AP2) * invDenom;
175 if ( (u >= 0) && (v >= 0) && (u + v < 1) ) {
182 const float dotAC_AP3 = ac.
dot(ap);
183 const float dotAB_AP3 = ab.
dot(ap);
184 const float u = (dotAB_AB * dotAC_AP3 - dotAC_AB * dotAB_AP3) * invDenom;
185 const float v = (dotAC_AC * dotAB_AP3 - dotAC_AB * dotAC_AP3) * invDenom;
188 if ( (u >= 0) && (v >= 0) && (u + v < 1) ) {
constexpr value_type dot(const Vector3F &o) const noexcept
Return the dot product of this vector and the given one.
Axis Aligned Bounding Box.
constexpr Vec3f midpoint(const Vec3f &a, const Vec3f &b) noexcept
constexpr bool isInTriangle3(const Vec3f &a, const Vec3f &b, const Vec3f &c, const Vec3f &p1, const Vec3f &p2, const Vec3f &p3) noexcept
Check if one of three vertices are in triangle using barycentric coordinates computation.
bool intersects(const AABBox3f &box) const noexcept
constexpr LineSeg3f & operator*=(const float s) noexcept
Scale this line segment with given scale factor.
bool intersects(Point3f &result, const LineSeg3f &o)
Compute intersection between two lines segments.
std::string toString() const noexcept
bool intersects(const LineSeg3f &o)
Compute intersection between two lines segments.