24#ifndef JAU_GEOM3F_HPP_
25#define JAU_GEOM3F_HPP_
53 std::string
toString() const noexcept {
return "L[" +
p0.toString() +
", " +
p1.toString() +
"]"; }
65 const float determinant = (
p0.x -
p1.x ) * ( o.
p0.
y - o.
p1.
y) - (
p0.y -
p1.y ) * ( o.
p0.
x - o.
p1.
x );
66 if( 0 == determinant ) {
69 const float alpha =
p0.x *
p1.y -
p0.y *
p1.x;
71 const float xi = ((o.
p0.
x-o.
p1.
x)*alpha-(
p0.x-
p1.x)*beta)/determinant;
73 const float gamma0 = (xi -
p0.x) / (
p1.x -
p0.x);
74 const float gamma1 = (xi - o.
p0.
x) / (o.
p1.
x - o.
p0.
x);
75 if(gamma0 <= 0 || gamma0 >= 1 || gamma1 <= 0 || gamma1 >= 1) {
78 const float yi = ((o.
p0.
y-o.
p1.
y)*alpha-(
p0.y-
p1.y)*beta)/determinant;
93 const float determinant = (
p0.x -
p1.x ) * ( o.
p0.
y - o.
p1.
y) - (
p0.y -
p1.y ) * ( o.
p0.
x - o.
p1.
x );
94 if( 0 == determinant ) {
97 const float alpha =
p0.x *
p1.y -
p0.y *
p1.x;
99 const float xi = ((o.
p0.
x-o.
p1.
x)*alpha-(
p0.x-
p1.x)*beta)/determinant;
101 const float gamma0 = (xi -
p0.x) / (
p1.x -
p0.x);
102 const float gamma1 = (xi - o.
p0.
x) / (o.
p1.
x - o.
p0.
x);
103 if(gamma0 <= 0 || gamma0 >= 1 || gamma1 <= 0 || gamma1 >= 1) {
112 const Vec3f e = (box.tr - box.bl) * 0.5f;
113 const Vec3f aabb_center = (box.bl + box.tr) * 0.5f;
114 const Vec3f lseg_center =
p0 + d;
115 const Vec3f c = lseg_center - aabb_center;
116 Vec3f ad(std::abs(d.
x), std::abs(d.
y), std::abs(d.
z));
117 if (std::abs(c.
x) > e.
x + ad.
x)
119 if (std::abs(c.
y) > e.
y + ad.
y)
121 if (std::abs(c.
z) > e.
z + ad.
z)
123 if (std::abs(d.
y * c.
z - d.
z * c.
y) > e.
y * ad.
z + e.
z * ad.
y + std::numeric_limits<float>::epsilon()) {
126 if (std::abs(d.
z * c.
x - d.
x * c.
z) > e.
z * ad.
x + e.
x * ad.
z + std::numeric_limits<float>::epsilon()) {
129 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.