Use the following to calculate the 2D distance between two points.
--- Specify pointslocal p1 = {x =3, y =4}local p2 = {x =6, y =8}--- Utils objectlocal dist = utils.geometry.distance_2d(p1, p2)print("2D Distance:", dist)--- Direct exportlocal dist = exports.boii_utils:distance_2d(p1, p2)
distance_3d
Use the following to calculate the 3D distance between two points.
--- Specify pointslocal p1 = {x =1, y =2, z =3}local p2 = {x =4, y =6, z =8}--- Utils objectlocal dist = utils.geometry.distance_3d(p1, p2)print('3D Distance:', dist)--- Direct exportlocal dist = exports.boii_utils:distance_3d(p1, p2)
midpoint
Use the following to calculate the midpoint between two 3D points.
--- Specify pointslocal p1 = {x =2, y =4, z =6}local p2 = {x =8, y =12, z =14}--- Utils objectlocal mid = utils.geometry.midpoint(p1, p2)print(string.format('Midpoint: (%.2f, %.2f, %.2f)', mid.x, mid.y, mid.z))--- Direct exportlocal 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 rectanglelocal point = {x =5, y =5}local rect = {x =0, y =0, width =10, height =10}--- Utils objectlocal inside = utils.geometry.is_point_in_rect(point, rect)print('Is point in rectangle:', inside)--- Direct exportlocal 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 boxlocal point = {x =5, y =5, z =5}local box = {x =0, y =0, z =0, width =10, height =10, depth =10}--- Utils objectlocal inside = utils.geometry.is_point_in_box(point, box)print('Is point in box:', inside)--- Direct exportlocal 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 segmentlocal point = {x =3, y =3}local line_start = {x =1, y =1}local line_end = {x =5, y =5}--- Utils objectlocal 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 exportlocal 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 segmentlocal point = {x =4, y =2}local line_start = {x =1, y =1}local line_end = {x =6, y =6}--- Utils objectlocal 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 exportlocal 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 pointslocal p1 = {x =1, y =2}local p2 = {x =4, y =6}--- Utils objectlocal slope = utils.geometry.calculate_slope(p1, p2)print('Slope of the line:', slope)--- Direct exportlocal 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 pointslocal p1 = {x =0, y =0}local p2 = {x =4, y =3}--- Utils objectlocal angle = utils.geometry.angle_between_points(p1, p2)print('Angle between points (degrees):', angle)--- Direct exportlocal 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 pointslocal p1 = {x =1, y =1, z =0}local p2 = {x =3, y =3, z =0} -- Center pointlocal p3 = {x =5, y =1, z =0}--- Utils objectlocal angle = utils.geometry.angle_between_3_points(p1, p2, p3)print('Angle between three points (degrees):', angle)--- Direct exportlocal 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.
Use the following to determine if a point is inside a circle defined by centre and radius.
--- Specify point and circlelocal point = {x =2, y =3}local circle_center = {x =0, y =0}local circle_radius =5--- Utils objectlocal inside = utils.geometry.is_point_in_circle(point, circle_center, circle_radius)print('Is point inside circle:', inside)--- Direct exportlocal 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 segmentslocal 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 objectlocal intersects = utils.geometry.do_lines_intersect(l1_start, l1_end, l2_start, l2_end)print('Do lines intersect:', intersects)--- Direct exportlocal 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 circlelocal 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 objectlocal intersects = utils.geometry.line_intersects_circle(line_start, line_end, circle_center, circle_radius)print('Does line intersect circle:', intersects)--- Direct exportlocal 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 linelocal rect = {x =1, y =1, width =4, height =3}local line_start = {x =0, y =0}local line_end = {x =6, y =4}--- Utils objectlocal intersects = utils.geometry.does_rect_intersect_line(rect, line_start, line_end)print('Does rectangle intersect line:', intersects)--- Direct exportlocal 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 segmentlocal point = {x =3, y =4}local line_start = {x =0, y =0}local line_end = {x =6, y =6}--- Utils objectlocal closest_point = utils.geometry.closest_point_on_line_segment(point, line_start, line_end)print('Closest Point on Line Segment:', closest_point)--- Direct exportlocal 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 pointslocal p1 = {x =0, y =0, z =0}local p2 = {x =5, y =0, z =0}local p3 = {x =0, y =5, z =0}--- Utils objectlocal area = utils.geometry.triangle_area_3d(p1, p2, p3)print('Area of 3D Triangle:', area)--- Direct exportlocal 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 spherelocal point = {x =2, y =2, z =2}local sphere_center = {x =0, y =0, z =0}local sphere_radius =5--- Utils objectlocal in_sphere = utils.geometry.is_point_in_sphere(point, sphere_center, sphere_radius)print('Is Point in Sphere:', in_sphere)--- Direct exportlocal 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 sphereslocal s1_center = {x =0, y =0, z =0}local s1_radius =5local s2_center = {x =6, y =6, z =6}local s2_radius =3--- Utils objectlocal spheres_intersect = utils.geometry.do_spheres_intersect(s1_center, s1_radius, s2_center, s2_radius)print('Do Spheres Intersect:', spheres_intersect)--- Direct exportlocal 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 polygonlocal point = {x =3, y =3}local polygon = { {x =0, y =0}, {x =6, y =0}, {x =6, y =6}, {x =0, y =6}}--- Utils objectlocal in_polygon = utils.geometry.is_point_in_convex_polygon(point, polygon)print('Is Point in Convex Polygon:', in_polygon)--- Direct exportlocal 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 anglelocal point = {x =10, y =5}local pivot = {x =0, y =0}local angle_degrees =45--- Utils objectlocal rotated_point = utils.geometry.rotate_point_around_point_2d(point, pivot, angle_degrees)print('Rotated Point:', rotated_point.x, rotated_point.y)--- Direct exportlocal 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 planelocal 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 objectlocal distance = utils.geometry.distance_point_to_plane(point, plane_point, plane_normal)print('Distance to Plane:', distance)--- Direct exportlocal 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 vectorlocal rotation = {x =45, y =0, z =90}--- Utils objectlocal direction = utils.geometry.rotation_to_direction(rotation)print('Direction Vector:', direction.x, direction.y, direction.z)--- Direct exportlocal 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 3Dlocal center = {x =0, y =0, z =0}local width =10local length =20local heading =90--- Utils objectlocal rotated_box = utils.geometry.rotate_box(center, width, length, heading)print('Rotated Box Corners:', rotated_box)--- Direct exportlocal 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 rolllocal heading =90local pitch =45local roll =0--- Utils objectlocal rotation_matrix = utils.geometry.calculate_rotation_matrix(heading, pitch, roll)print('Rotation Matrix:', rotation_matrix)--- Direct exportlocal 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 systemlocal 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 objectlocal 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 exportlocal 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 boxlocal 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 objectlocal is_inside = utils.geometry.is_point_in_oriented_box(point, box)print('Is Point Inside Oriented Box:', is_inside)--- Direct exportlocal is_inside = exports.boii_utils:is_point_in_oriented_box(point, box)