[De...] Posted March 13 Share Posted March 13 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: 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? 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 More sharing options...
[Ma...] Posted March 13 Share Posted March 13 (edited) 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 March 13 Link to comment Share on other sites More sharing options...
[De...] Posted March 14 Author Share Posted March 14 Thank you Matthias! 😃 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 More sharing options...
[Ma...] Posted March 26 Share Posted March 26 👍 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in