# Geometry

{% hint style="warning" %}
**SHARED FUNCTIONS**
{% endhint %}

## distance\_2d

Calculates the distance between two 2D points.

#### Parameters

* p1: `table`
* p2: `table`

#### Returns

* `number`

```lua
bdtk.distance_2d(p1, p2)
```

***

## distance\_3d

Calculates the distance between two 3D points.

#### Parameters

* p1: `table`
* p2: `table`

#### Returns

* `number`

```lua
bdtk.distance_3d(p1, p2)
```

***

## midpoint

Returns the midpoint between two 3D points.

#### Parameters

* p1: `table`
* p2: `table`

#### Returns

* `table`

```lua
bdtk.midpoint(p1, p2)
```

***

## is\_point\_in\_rect

Determines if a point is inside a given 2D rectangle boundary.

#### Parameters

* point: `table`
* rect: `table`

#### Returns

* `boolean`

```lua
bdtk.is_point_in_rect(point, rect)
```

***

## is\_point\_in\_box

Determines if a point is inside a given 3D box boundary.

#### Parameters

* point: `table`
* box: `table`

#### Returns

* `boolean`

```lua
bdtk.is_point_in_box(point, box)
```

***

## is\_point\_on\_line\_segment

Determines if a point is on a line segment defined by two 2D points.

#### Parameters

* point: `table`
* line\_start: `table`
* line\_end: `table`

#### Returns

* `boolean`

```lua
bdtk.is_point_on_line_segment(point, line_start, line_end)
```

***

## project\_point\_on\_line

Projects a point onto a line segment defined by two 2D points.

#### Parameters

* p: `table`
* p1: `table`
* p2: `table`

#### Returns

* `table`

```lua
bdtk.project_point_on_line(p, p1, p2)
```

***

## calculate\_slope

Calculates the slope of a line given two 2D points.

#### Parameters

* p1: `table`
* p2: `table`

#### Returns

* `number`

```lua
bdtk.calculate_slope(p1, p2)
```

***

## angle\_between\_points

Returns the angle between two 2D points in degrees.

#### Parameters

* p1: `table`
* p2: `table`

#### Returns

* `number`

```lua
bdtk.angle_between_points(p1, p2)
```

***

## angle\_between\_3\_points

Calculates the angle between three 3D points (p1, p2 as center, p3).

#### Parameters

* p1: `table`
* p2: `table`
* p3: `table`

#### Returns

* `number`

```lua
bdtk.angle_between_3_points(p1, p2, p3)
```

***

## do\_circles\_intersect

Determines if two circles defined by center and radius intersect.

#### Parameters

* c1\_center: `table`
* c1\_radius: `number`
* c2\_center: `table`
* c2\_radius: `number`

#### Returns

* `boolean`

```lua
bdtk.do_circles_intersect(c1_center, c1_radius, c2_center, c2_radius)
```

***

## is\_point\_in\_circle

Determines if a point is inside a circle defined by center and radius.

#### Parameters

* point: `table`
* circle\_center: `table`
* circle\_radius: `number`

#### Returns

* `boolean`

```lua
bdtk.is_point_in_circle(point, circle_center, circle_radius)
```

***

## do\_lines\_intersect

Determines if two 2D line segments intersect.

#### Parameters

* l1\_start: `table`
* l1\_end: `table`
* l2\_start: `table`
* l2\_end: `table`

#### Returns

* `boolean`

```lua
bdtkbdtk.do_lines_intersect(l1_start, l1_end, l2_start, l2_end)
```

***

## line\_intersects\_circle

Determines if a line segment intersects a circle.

#### Parameters

* line\_start: `table`
* line\_end: `table`
* circle\_center: `table`
* circle\_radius: `number`

#### Returns

* `boolean`

```lua
bdtk.line_intersects_circle(line_start, line_end, circle_center, circle_radius)
```

***

## does\_rect\_intersect\_line

Determines if a rectangle intersects with a 2D line segment.

#### Parameters

* rect: `table`
* line\_start: `table`
* line\_end: `table`

#### Returns

* `boolean`

```lua
bdtk.does_rect_intersect_line(rect, line_start, line_end)
```

***

## closest\_point\_on\_line\_segment

Determines the closest point on a 2D line segment to a given point.

#### Parameters

* point: `table`
* line\_start: `table`
* line\_end: `table`

#### Returns

* `table`

```lua
bdtk.closest_point_on_line_segment(point, line_start, line_end)
```

***

## triangle\_area\_3d

Calculates the area of a 3D triangle given three points.

#### Parameters

* p1: `table`
* p2: `table`
* p3: `table`

#### Returns

* `number`

```lua
bdtk.triangle_area_3d(p1, p2, p3)
```

***

## is\_point\_in\_sphere

Determines if a point is inside a 3D sphere defined by center and radius.

#### Parameters

* point: `table`
* sphere\_center: `table`
* sphere\_radius: `number`

#### Returns

* `boolean`

```lua
bdtk.is_point_in_sphere(point, sphere_center, sphere_radius)
```

***

## do\_spheres\_intersect

Determines if two spheres intersect.

#### Parameters

* s1\_center: `table`
* s1\_radius: `number`
* s2\_center: `table`
* s2\_radius: `number`

#### Returns

* `boolean`

```lua
bdtk.do_spheres_intersect(s1_center, s1_radius, s2_center, s2_radius)
```

***

## is\_point\_in\_convex\_polygon

Determines if a point is inside a 2D convex polygon.

#### Parameters

* point: `table`
* polygon: `table`

#### Returns

* `boolean`

```lua
bdtk.is_point_in_convex_polygon(point, polygon)
```

***

## rotate\_point\_around\_point\_2d

Rotates a point around another point in 2D by a given angle in degrees.

#### Parameters

* point: `table`
* pivot: `table`
* angle\_degrees: `number`

#### Returns

* `table`

```lua
bdtk.rotate_point_around_point_2d(point, pivot, angle_degrees)
```

***

## distance\_point\_to\_plane

Calculates the distance from a point to a plane.

#### Parameters

* point: `table`
* plane\_point: `table`
* plane\_normal: `table`

#### Returns

* `number`

```lua
bdtk.distance_point_to_plane(point, plane_point, plane_normal)
```

***

## rotation\_to\_direction

Converts a rotation vector to a direction vector.

#### Parameters

* rotation: `table`

#### Returns

* `table`

```lua
bdtk.rotation_to_direction(rotation)
```

***

## rotate\_box

Rotates a box around a central point in 3D by a given heading.

#### Parameters

* center: `table`
* width: `number`
* length: `number`
* heading: `number`

#### Returns

* `table`

```lua
bdtk.rotate_box(center, width, length, heading)
```

***

## calculate\_rotation\_matrix

Calculates a rotation matrix from heading, pitch, and roll.

#### Parameters

* heading: `number`
* pitch: `number`
* roll: `number`

#### Returns

* `table`

```lua
geometry.calculate_rotation_matrix(heading, pitch, roll)
```

***

## translate\_point\_to\_local\_space

Translates a point to a box's local coordinate system using a rotation matrix.

#### Parameters

* point: `table`
* box\_origin: `table`
* rot\_matrix: `table`

#### Returns

* `table`

```lua
bdtk.translate_point_to_local_space(point, box_origin, rot_matrix)
```

***

## is\_point\_in\_oriented\_box

Determines if a point is inside an oriented 3D box.

#### Parameters

* point: `table`
* box: `table`

#### Returns

* `boolean`

```lua
bdtk.is_point_in_oriented_box(point, box)
```
