Module math.intersect
Various geometric intersections.
this is apart of the LEEF-math module. note that everything within this module uses CPML types. Since this had no documentation initially, documentation is a WIP.
Functions
point_aabb (point, aabb) | check if a point is inside an Axis Aligned Bounding Box |
point_frustum (point, frustum) | check if a point intersects with a frustum |
ray_triangle (ray, triangle, backface_cull) | check wether an infinite ray intersects with a triangle |
ray_sphere (ray, sphere) | check if a ray and a sphere intersect |
ray_aabb (ray, aabb) | check if a ray and an aabb |
ray_plane (ray, plane) | check if a ray and a plane intersect |
ray_capsule (ray, capsule) | check if a ray intersects a capsule |
line_line (a, b, e) | compute the shortest line segment between two lines |
segment_segment (a, b, e) | the same as line_line but the lines represent segments (which are not infinite) |
aabb_aabb (a, b) | check if two aabbs intersect |
aabb_obb (aabb, obb) | check if an aabb and a obb (oriented bounding box) intersect WARNING: this does not use the previously established system for aabbs |
aabb_sphere (aabb, sphere) | check wheter an aabb and sphere intersection |
aabb_frustum (aabb, frustum) | check if an aabb and frustum intersect |
encapsulate_aabb (outer, inner) | check if an aabb encapsulates (contains fully) another aabb |
sphere_sphere (a, b) | check if two spheres intersect |
sphere_triangle (sphere, triangle) | check if a sphere and a triangle intersect |
sphere_frustum (sphere, frustum) | check if a sphere intersects with a frustum |
capsule_capsule (c1, c2) | check if two capsules intersect |
Tables
frustum | A frustum
where a , b , c and d are vec3s |
ray | An infinite ray |
sphere | A sphere |
triangle | A 3d triangle |
aabb | An axis aligned bounding box |
plane | An infinite plane |
capsule | a segment with a radius |
Functions
- point_aabb (point, aabb)
-
check if a point is inside an Axis Aligned Bounding Box
Parameters:
- point vec3
- aabb table aabb
Returns:
-
bool
- point_frustum (point, frustum)
-
check if a point intersects with a frustum
Parameters:
- point vec3
- frustum table a frustum
Returns:
-
bool
- ray_triangle (ray, triangle, backface_cull)
-
check wether an infinite ray intersects with a triangle
Parameters:
- ray table ray
- triangle table triangle
- backface_cull bool (optional) wether backface culling is enabled
Returns:
- (false | Vec3) false if does not intersect, intersection point if true
- (nil | float) distance from ray origin
- ray_sphere (ray, sphere)
-
check if a ray and a sphere intersect
Parameters:
Returns:
- (false | Vec3) false if does not intersect, intersection point if true
- (nil | float) distance from ray origin
- ray_aabb (ray, aabb)
-
check if a ray and an aabb
Parameters:
Returns:
- (false | Vec3) false if does not intersect, intersection point if true
- (nil | float) distance from ray origin
- ray_plane (ray, plane)
-
check if a ray and a plane intersect
Parameters:
Returns:
- (false | Vec3) false if does not intersect, intersection point if true
- (nil | float) distance from ray origin
- ray_capsule (ray, capsule)
-
check if a ray intersects a capsule
Parameters:
Returns:
-
(false | Vec3) closest point on line to ray
- line_line (a, b, e)
-
compute the shortest line segment between two lines
Parameters:
- a table line {vec3, vec3}
- b table line {vec3, vec3}
- e float (optional) the minimum distance between the two lines
Returns:
- (false | table). Closest points on both lines: {vec3, vec3}, where the first vector is a, and second b.
- (nil | vec3). Distance between the lines
- segment_segment (a, b, e)
-
the same as line_line but the lines represent segments (which are not infinite)
Parameters:
- a table segment {vec3, vec3}
- b table segment {vec3, vec3}
- e float (optional) the minimum distance between the two lines
Returns:
- (false | table). Closest points on both segments: {vec3, vec3}, where the first vector is a, and second b.
- (nil | float). Distance between the segments
- aabb_aabb (a, b)
-
check if two aabbs intersect
Parameters:
Returns:
-
bool
- aabb_obb (aabb, obb)
-
check if an aabb and a obb (oriented bounding box) intersect
WARNING: this does not use the previously established system for aabbs
Parameters:
- aabb
table
{position=vec3, extent=vec3}
where position is the center of the object, and extent is the width on each axis. - obb
table
{position=vec3, extent=vec3, rotation=mat4}
Returns:
-
(false | vec3). Side of the obb that intersects
- aabb
table
- aabb_sphere (aabb, sphere)
-
check wheter an aabb and sphere intersection
Parameters:
Returns:
-
bool
- aabb_frustum (aabb, frustum)
-
check if an aabb and frustum intersect
Parameters:
Returns:
-
bool
- encapsulate_aabb (outer, inner)
-
check if an aabb encapsulates (contains fully) another aabb
Parameters:
Returns:
-
bool
- sphere_sphere (a, b)
-
check if two spheres intersect
Parameters:
Returns:
-
bool
- sphere_triangle (sphere, triangle)
-
check if a sphere and a triangle intersect
Parameters:
Returns:
-
bool
- sphere_frustum (sphere, frustum)
-
check if a sphere intersects with a frustum
Parameters:
Returns:
-
(false | float) distance from the nearplane
- capsule_capsule (c1, c2)
-
check if two capsules intersect
Parameters:
- c1 table capsule
- c2 table capsule
Returns:
- (false | Vec3) false if no intersections, vec3 on the first capsule's line if intersection occours
- (nil | Vec3) second line intersect
Tables
- frustum
-
A frustum
where
a
,b
,c
andd
are vec3sFields:
- left
plane
{a, b, c, d}
- right
plane
{a, b, c, d}
- bottom
plane
{a, b, c, d}
- top
plane
{a, b, c, d}
- near
plane
{a, b, c, d}
- far
plane
{a, b, c, d}
(optional)
- left
plane
- ray
-
An infinite ray
Fields:
- direction (vec3)
- position (vec3)
- sphere
-
A sphere
Fields:
- position (vec3)
- radius (float)
- triangle
-
A 3d triangle
Fields:
- 1 (vec3)
- 2 (vec3)
- 3 (vec3)
- aabb
-
An axis aligned bounding box
Fields:
- min (vec3)
- max (vec3)
- plane
-
An infinite plane
Fields:
- position (vec3)
- normal (vec3) "upward" direction of the plane
- capsule
-
a segment with a radius
Fields:
- a (vec3) first position of the "segment"
- b (vec3) second position of the "segment"
- radius (float)