Skip to content

Commit

Permalink
Add bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhankoral committed Oct 11, 2023
1 parent b1177a2 commit f354fa0
Show file tree
Hide file tree
Showing 6 changed files with 1,247 additions and 1 deletion.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python 3.11.6
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"test"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
43 changes: 43 additions & 0 deletions archaea/geometry/bounding_box.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from archaea.geometry.point3d import Point3d


class BoundingBox:
min: Point3d
max: Point3d
center: Point3d
area: float
volume: float

def __init__(self, minX: float, minY: float, minZ: float, maxX: float, maxY: float, maxZ: float) -> None:
self.min = Point3d(minX, minY, minZ)
self.max = Point3d(maxX, maxY, maxZ)
self.__calculate_values()

@classmethod
def from_points(cls, points: "list[Point3d]"):
x_values = [p.x for p in points]
y_values = [p.y for p in points]
z_values = [p.z for p in points]
min_x = min(x_values)
min_y = min(y_values)
min_z = min(z_values)
max_x = max(x_values)
max_y = max(y_values)
max_z = max(z_values)
return cls(min_x, min_y, min_z, max_x, max_y, max_z)

@classmethod
def from_2_points(cls, p1: Point3d, p2: Point3d):
return cls.from_points([p1, p2])

def __calculate_values(self):
self.center = Point3d(
(self.max.x + self.min.x) / 2,
(self.max.y + self.min.y) / 2,
(self.max.z + self.min.z) / 2
)
x_dist = abs(self.max.x - self.min.x)
y_dist = abs(self.max.y - self.min.y)
z_dist = abs(self.max.z - self.min.z)
self.volume = x_dist * y_dist * z_dist
self.area = 2 * ((x_dist * y_dist) + (x_dist * z_dist) + (y_dist * z_dist))
Loading

0 comments on commit f354fa0

Please sign in to comment.