11#ifndef JAU_MATH_GEOM_GEOM3F_HPP_
12#define JAU_MATH_GEOM_GEOM3F_HPP_
40 std::string
toString() const noexcept {
return "L[" +
p0.toString() +
", " +
p1.toString() +
"]"; }
52 const float determinant = (
p0.x -
p1.x ) * ( o.
p0.
y - o.
p1.
y) - (
p0.y -
p1.y ) * ( o.
p0.
x - o.
p1.
x );
53 if( 0 == determinant ) {
56 const float alpha =
p0.x *
p1.y -
p0.y *
p1.x;
58 const float xi = ((o.
p0.
x-o.
p1.
x)*alpha-(
p0.x-
p1.x)*beta)/determinant;
60 const float gamma0 = (xi -
p0.x) / (
p1.x -
p0.x);
61 const float gamma1 = (xi - o.
p0.
x) / (o.
p1.
x - o.
p0.
x);
62 if(gamma0 <= 0 || gamma0 >= 1 || gamma1 <= 0 || gamma1 >= 1) {
65 const float yi = ((o.
p0.
y-o.
p1.
y)*alpha-(
p0.y-
p1.y)*beta)/determinant;
80 const float determinant = (
p0.x -
p1.x ) * ( o.
p0.
y - o.
p1.
y) - (
p0.y -
p1.y ) * ( o.
p0.
x - o.
p1.
x );
81 if( 0 == determinant ) {
84 const float alpha =
p0.x *
p1.y -
p0.y *
p1.x;
86 const float xi = ((o.
p0.
x-o.
p1.
x)*alpha-(
p0.x-
p1.x)*beta)/determinant;
88 const float gamma0 = (xi -
p0.x) / (
p1.x -
p0.x);
89 const float gamma1 = (xi - o.
p0.
x) / (o.
p1.
x - o.
p0.
x);
90 if(gamma0 <= 0 || gamma0 >= 1 || gamma1 <= 0 || gamma1 >= 1) {
99 const Vec3f e = (box.tr - box.bl) * 0.5f;
100 const Vec3f aabb_center = (box.bl + box.tr) * 0.5f;
101 const Vec3f lseg_center =
p0 + d;
102 const Vec3f c = lseg_center - aabb_center;
103 Vec3f ad(std::abs(d.
x), std::abs(d.
y), std::abs(d.
z));
104 if (std::abs(c.
x) > e.
x + ad.
x)
106 if (std::abs(c.
y) > e.
y + ad.
y)
108 if (std::abs(c.
z) > e.
z + ad.
z)
110 if (std::abs(d.
y * c.
z - d.
z * c.
y) > e.
y * ad.
z + e.
z * ad.
y + std::numeric_limits<float>::epsilon()) {
113 if (std::abs(d.
z * c.
x - d.
x * c.
z) > e.
z * ad.
x + e.
x * ad.
z + std::numeric_limits<float>::epsilon()) {
116 if (std::abs(d.
x * c.
y - d.
y * c.
x) > e.
x * ad.
y + e.
y * ad.
x + std::numeric_limits<float>::epsilon()) {
Axis Aligned Bounding Box.
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.