Use the following to calculate the 2D distance between two points.
--- Specify points
local p1 = {x = 3, y = 4}
local p2 = {x = 6, y = 8}
--- Utils object
local dist = utils.geometry.distance_2d(p1, p2)
print("2D Distance:", dist)
--- Direct export
local dist = exports.boii_utils:distance_2d(p1, p2)
distance_3d
Use the following to calculate the 3D distance between two points.
--- Specify points
local p1 = {x = 1, y = 2, z = 3}
local p2 = {x = 4, y = 6, z = 8}
--- Utils object
local dist = utils.geometry.distance_3d(p1, p2)
print('3D Distance:', dist)
--- Direct export
local dist = exports.boii_utils:distance_3d(p1, p2)
midpoint
Use the following to calculate the midpoint between two 3D points.
--- Specify points
local p1 = {x = 2, y = 4, z = 6}
local p2 = {x = 8, y = 12, z = 14}
--- Utils object
local mid = utils.geometry.midpoint(p1, p2)
print(string.format('Midpoint: (%.2f, %.2f, %.2f)', mid.x, mid.y, mid.z))
--- Direct export
local mid = exports.boii_utils:midpoint(p1, p2)
is_point_in_rect
Use the following to determine if a point is inside a given 2D boundary.
--- Specify point and rectangle
local point = {x = 5, y = 5}
local rect = {x = 0, y = 0, width = 10, height = 10}
--- Utils object
local inside = utils.geometry.is_point_in_rect(point, rect)
print('Is point in rectangle:', inside)
--- Direct export
local inside = exports.boii_utils:is_point_in_rect(point, rect)
is_point_in_box
Use the following to determine if a point is inside a £D boundary.
--- Specify point and box
local point = {x = 5, y = 5, z = 5}
local box = {x = 0, y = 0, z = 0, width = 10, height = 10, depth = 10}
--- Utils object
local inside = utils.geometry.is_point_in_box(point, box)
print('Is point in box:', inside)
--- Direct export
local inside = exports.boii_utils:is_point_in_box(point, box)
is_point_on_line_segment
Use the following to determine if a point is on a line segment defined by two 2D points.
--- Specify point and line segment
local point = {x = 3, y = 3}
local line_start = {x = 1, y = 1}
local line_end = {x = 5, y = 5}
--- Utils object
local is_on_line = utils.geometry.is_point_on_line_segment(point, line_start, line_end)
print('Is point on line segment:', is_on_line)
--- Direct export
local is_on_line = exports.boii_utils:is_point_on_line_segment(point, line_start, line_end)
project_point_on_line
Use the following to project a point onto a line segment defined by two 2D points.
--- Specify point and line segment
local point = {x = 4, y = 2}
local line_start = {x = 1, y = 1}
local line_end = {x = 6, y = 6}
--- Utils object
local projected_point = utils.geometry.project_point_on_line(point, line_start, line_end)
print(string.format('Projected Point: (%.2f, %.2f)', projected_point.x, projected_point.y))
--- Direct export
local projected_point = exports.boii_utils:project_point_on_line(point, line_start, line_end)
calculate_slope
Use the following to calculate the slope of a line between two 2D points.
--- Specify points
local p1 = {x = 1, y = 2}
local p2 = {x = 4, y = 6}
--- Utils object
local slope = utils.geometry.calculate_slope(p1, p2)
print('Slope of the line:', slope)
--- Direct export
local slope = exports.boii_utils:calculate_slope(p1, p2)
angle_between_points
Use the following to return the angle between two 2D points in degrees.
--- Specify points
local p1 = {x = 0, y = 0}
local p2 = {x = 4, y = 3}
--- Utils object
local angle = utils.geometry.angle_between_points(p1, p2)
print('Angle between points (degrees):', angle)
--- Direct export
local angle = exports.boii_utils:angle_between_points(p1, p2)
angle_between_3_points
Use the following to calculate the angle between three 3D points.
--- Specify three points
local p1 = {x = 1, y = 1, z = 0}
local p2 = {x = 3, y = 3, z = 0} -- Center point
local p3 = {x = 5, y = 1, z = 0}
--- Utils object
local angle = utils.geometry.angle_between_3_points(p1, p2, p3)
print('Angle between three points (degrees):', angle)
--- Direct export
local angle = exports.boii_utils:angle_between_3_points(p1, p2, p3)
do_circles_intersect
Use the following to determine if two circles defined by centre and radius intersect.
--- Specify circles
local c1_center = {x = 0, y = 0}
local c1_radius = 5
local c2_center = {x = 3, y = 4}
local c2_radius = 3
--- Utils object
local intersects = utils.geometry.do_circles_intersect(c1_center, c1_radius, c2_center, c2_radius)
print('Do circles intersect:', intersects)
--- Direct export
local intersects = exports.boii_utils:do_circles_intersect(c1_center, c1_radius, c2_center, c2_radius)
is_point_in_circle
Use the following to determine if a point is inside a circle defined by centre and radius.
--- Specify point and circle
local point = {x = 2, y = 3}
local circle_center = {x = 0, y = 0}
local circle_radius = 5
--- Utils object
local inside = utils.geometry.is_point_in_circle(point, circle_center, circle_radius)
print('Is point inside circle:', inside)
--- Direct export
local inside = exports.boii_utils:is_point_in_circle(point, circle_center, circle_radius)
do_lines_intersect
Use the following to determine if two 2D line segments intersect.
--- Specify line segments
local l1_start = {x = 0, y = 0}
local l1_end = {x = 5, y = 5}
local l2_start = {x = 0, y = 5}
local l2_end = {x = 5, y = 0}
--- Utils object
local intersects = utils.geometry.do_lines_intersect(l1_start, l1_end, l2_start, l2_end)
print('Do lines intersect:', intersects)
--- Direct export
local intersects = exports.boii_utils:do_lines_intersect(l1_start, l1_end, l2_start, l2_end)
line_intersects_circle
Use the following to determine if a line segment intersects a circle.
--- Specify line and circle
local line_start = {x = -1, y = 0}
local line_end = {x = 6, y = 0}
local circle_center = {x = 2.5, y = 0}
local circle_radius = 3
--- Utils object
local intersects = utils.geometry.line_intersects_circle(line_start, line_end, circle_center, circle_radius)
print('Does line intersect circle:', intersects)
--- Direct export
local intersects = exports.boii_utils:line_intersects_circle(line_start, line_end, circle_center, circle_radius)
does_rect_intersect_line
Use the following to determine if a rectangle intersects with a 2D line segment.
--- Specify rectangle and line
local rect = {x = 1, y = 1, width = 4, height = 3}
local line_start = {x = 0, y = 0}
local line_end = {x = 6, y = 4}
--- Utils object
local intersects = utils.geometry.does_rect_intersect_line(rect, line_start, line_end)
print('Does rectangle intersect line:', intersects)
--- Direct export
local intersects = exports.boii_utils:does_rect_intersect_line(rect, line_start, line_end)
closest_point_on_line_segment
Use the following to determine the closest point on a 2D line segment to a given point.
--- Specify point and line segment
local point = {x = 3, y = 4}
local line_start = {x = 0, y = 0}
local line_end = {x = 6, y = 6}
--- Utils object
local closest_point = utils.geometry.closest_point_on_line_segment(point, line_start, line_end)
print('Closest Point on Line Segment:', closest_point)
--- Direct export
local closest_point = exports.boii_utils:closest_point_on_line_segment(point, line_start, line_end)
triangle_area_3d
Use the following to calculate the area of a 3D triangle.
--- Specify triangle points
local p1 = {x = 0, y = 0, z = 0}
local p2 = {x = 5, y = 0, z = 0}
local p3 = {x = 0, y = 5, z = 0}
--- Utils object
local area = utils.geometry.triangle_area_3d(p1, p2, p3)
print('Area of 3D Triangle:', area)
--- Direct export
local area = exports.boii_utils:triangle_area_3d(p1, p2, p3)
is_point_in_sphere
Use the following to determine if a point is inside a 3D sphere.
--- Specify point and sphere
local point = {x = 2, y = 2, z = 2}
local sphere_center = {x = 0, y = 0, z = 0}
local sphere_radius = 5
--- Utils object
local in_sphere = utils.geometry.is_point_in_sphere(point, sphere_center, sphere_radius)
print('Is Point in Sphere:', in_sphere)
--- Direct export
local in_sphere = exports.boii_utils:is_point_in_sphere(point, sphere_center, sphere_radius)
do_spheres_intersect
Use the following to determine if two spheres intersect.
--- Specify spheres
local s1_center = {x = 0, y = 0, z = 0}
local s1_radius = 5
local s2_center = {x = 6, y = 6, z = 6}
local s2_radius = 3
--- Utils object
local spheres_intersect = utils.geometry.do_spheres_intersect(s1_center, s1_radius, s2_center, s2_radius)
print('Do Spheres Intersect:', spheres_intersect)
--- Direct export
local spheres_intersect = exports.boii_utils:do_spheres_intersect(s1_center, s1_radius, s2_center, s2_radius)
is_point_in_convex_polygon
Use the following to determine if a point is inside a 2D convex polygon.
--- Specify point and polygon
local point = {x = 3, y = 3}
local polygon = {
{x = 0, y = 0},
{x = 6, y = 0},
{x = 6, y = 6},
{x = 0, y = 6}
}
--- Utils object
local in_polygon = utils.geometry.is_point_in_convex_polygon(point, polygon)
print('Is Point in Convex Polygon:', in_polygon)
--- Direct export
local in_polygon = exports.boii_utils:is_point_in_convex_polygon(point, polygon)
rotate_point_around_point_2d
Use the following to rotation a point around another point in a 2D space.
--- Rotate a point around another point in 2D by a given angle
local point = {x = 10, y = 5}
local pivot = {x = 0, y = 0}
local angle_degrees = 45
--- Utils object
local rotated_point = utils.geometry.rotate_point_around_point_2d(point, pivot, angle_degrees)
print('Rotated Point:', rotated_point.x, rotated_point.y)
--- Direct export
local rotated_point = exports.boii_utils:rotate_point_around_point_2d(point, pivot, angle_degrees)
distance_point_to_plane
Use the following to calculate the distance from a point to a plane.
--- Distance from a point to a plane
local point = {x = 10, y = 5, z = 8}
local plane_point = {x = 0, y = 0, z = 0}
local plane_normal = {x = 0, y = 0, z = 1}
--- Utils object
local distance = utils.geometry.distance_point_to_plane(point, plane_point, plane_normal)
print('Distance to Plane:', distance)
--- Direct export
local distance = exports.boii_utils:distance_point_to_plane(point, plane_point, plane_normal)
rotation_to_direction
Use the following to convert a rotation vector to a direction vector.
--- Convert rotation to direction vector
local rotation = {x = 45, y = 0, z = 90}
--- Utils object
local direction = utils.geometry.rotation_to_direction(rotation)
print('Direction Vector:', direction.x, direction.y, direction.z)
--- Direct export
local direction = exports.boii_utils:rotation_to_direction(rotation)
rotate_box
Use the following to rotate a box around a central point in a 3D space.
--- Rotate a box around a central point in 3D
local center = {x = 0, y = 0, z = 0}
local width = 10
local length = 20
local heading = 90
--- Utils object
local rotated_box = utils.geometry.rotate_box(center, width, length, heading)
print('Rotated Box Corners:', rotated_box)
--- Direct export
local rotated_box = exports.boii_utils:rotate_box(center, width, length, heading)
calculate_rotation_matrix
Use the following to calculate a rotation matrix from heading, pitch and roll.
--- Calculate a rotation matrix from heading, pitch, and roll
local heading = 90
local pitch = 45
local roll = 0
--- Utils object
local rotation_matrix = utils.geometry.calculate_rotation_matrix(heading, pitch, roll)
print('Rotation Matrix:', rotation_matrix)
--- Direct export
local rotation_matrix = exports.boii_utils:calculate_rotation_matrix(heading, pitch, roll)
translate_point_to_local_space
Use the following to translate a point to a box's local coordinate system using a rotation matrix.
--- Translate a point to a box's local coordinate system
local point = {x = 10, y = 5, z = 3}
local box_origin = {x = 0, y = 0, z = 0}
local rot_matrix = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}
--- Utils object
local local_space_point = utils.geometry.translate_point_to_local_space(point, box_origin, rot_matrix)
print('Point in Local Space:', local_space_point.x, local_space_point.y, local_space_point.z)
--- Direct export
local local_space_point = exports.boii_utils:translate_point_to_local_space(point, box_origin, rot_matrix)
is_point_in_orientated_box
Use the following to determine if a point is inside an orentated 3D box.
--- Check if a point is inside an oriented 3D box
local point = {x = 1, y = 2, z = 3}
local box = {
coords = {x = 0, y = 0, z = 0},
width = 10,
height = 5,
depth = 7,
heading = 45,
pitch = 10,
roll = 0
}
--- Utils object
local is_inside = utils.geometry.is_point_in_oriented_box(point, box)
print('Is Point Inside Oriented Box:', is_inside)
--- Direct export
local is_inside = exports.boii_utils:is_point_in_oriented_box(point, box)