Jump to content
Private Messaging is activated - check "How to" on how to disable it ×

Bounding Box Attributes


---
 Share

Recommended Posts

---

Hi, I was wondering if anyone knew how to utilize the bounding box attributes?
As an example, lets take a patch compound created on a subset of surface patches.

Here's a random patch compound as an example:
image.thumb.png.9e55b5d85707c787e498478c4e19063a.png


image.thumb.png.176d64773016b7dd411a522cd63f60ae.png

The bounding box min attribute = gom.Vec3d(x,y,z)
maximum =  gom.Vec3d(x,y,z)
what do these #s represent? How does 1 point represent a box?


image.png.3ce1ec2b35993fc74cad8fa54793957a.pngimage.png.e9d605db21a072af6754943f5080376a.png

I'm trying to determine the bounding box / center point of a patch compound (ideally without creating fitting points/elements).
Any help would be greatly appreciated!
-Devon

Link to comment
Share on other sites

---

Hi Devon,

Just a wild guess: Maybe the bounding box is defined by two opposite corners defined by the minimum/maximum coordinates?

Best regards,

Matthias

 

Edited
Link to comment
Share on other sites

---

Thank you Matthias!  😃
image.thumb.png.e4d9ff9359a13157d155a7cae8ee682e.png

def extract_bounding_box(obj):
	# Extract the minimum point coordinates
	x_min = obj.bounding_box.min.x
	y_min = obj.bounding_box.min.y
	z_min = obj.bounding_box.min.z
	
	# Extract the maximum point coordinates
	x_max = obj.bounding_box.max.x
	y_max = obj.bounding_box.max.y
	z_max = obj.bounding_box.max.z
	
	# Generate the 8 corners of the bounding box
	corners = [
		(x_min, y_min, z_min),
		(x_min, y_min, z_max),
		(x_min, y_max, z_min),
		(x_min, y_max, z_max),
		(x_max, y_min, z_min),
		(x_max, y_min, z_max),
		(x_max, y_max, z_min),
		(x_max, y_max, z_max)
	]
	
	# Compute the center point of the bounding box
	center = [
		(x_min + x_max) / 2,
		(y_min + y_max) / 2,
		(z_min + z_max) / 2
	]
	
	# Calculate the dimensions: length (x-axis), width (y-axis), height (z-axis)
	length = x_max - x_min
	width  = y_max - y_min
	height = z_max - z_min
	
	return corners, center, length, width, height


obj = gom.app.project.inspection['random_surface']

corners, center, length, width, height = extract_bounding_box(obj)

print("Corners:", corners)
print("Center:", center)
print("Dimensions (Length, Width, Height):", length, width, height)


MCAD_ELEMENT=gom.script.primitive.create_cuboid_by_point_direction (
	center_point={'point': gom.Vec3d(center[0], center[1], center[2])}, 
	dimension_1=length, 
	dimension_1_direction={'direction': gom.Vec3d (1.0, 0.0, 0.0), 'point': gom.Vec3d (0.0, 0.0, 0.0), 'type': 'projected'}, 
	dimension_2=width, 
	dimension_2_direction={'direction': gom.Vec3d (0.0, 1.0, 0.0), 'point': gom.Vec3d (0.0, 0.0, 0.0), 'type': 'projected'}, 
	dimension_3=height, 
	name='Cuboid 1', 
	offset_value=0.0)

 

Link to comment
Share on other sites

  • 2 weeks later...
 Share

×
×
  • Create New...