Menu

get_bbox - global / local coordinates issue

2023-09-15
2023-09-15
  • PeterPetersen

    PeterPetersen - 2023-09-15

    I have just realised that the getbbox function gets me the bounding box according to global coordinates. This means that when I use it to calculate size of objects that are rotated from XYZ axes I get incorrect results. Is there any way to use this on the local coordinates? E.g. is there an equivalent of vertices = getvertices(geometry) getting the vertices as per local object's coordinates?

     

    Last edit: PeterPetersen 2023-09-15
  • PeterPetersen

    PeterPetersen - 2023-09-15

    Following further investigation the issue seems to be somewhat more complex. For some strange reason IfcWalls and IfcDoors (rotated from XY axes) are calculated correctly, whereas IfcSlabs, Beams etc. are calculated wrong when using exactly the same formula. Would be greatful for any hints! Below the code I am using:

    def get_bbox_local(file, entity): 
        settings = ifcopenshell.geom.settings()
        elements = file.by_type(entity)
        for element in elements:
            shape = ifcopenshell.geom.create_shape(settings, element)
            geometry = shape.geometry  
            vertices = get_vertices(geometry)
            bbox = get_bbox(vertices)
            min_coords, max_coords = bbox
    
            # Extract individual min and max values for x, y, z
            minx, miny, minz = min_coords
            maxx, maxy, maxz = max_coords
    
            # Calculate dimensions
            length_x = maxx - minx
            width_y = maxy - miny
            height_z = maxz - minz
    
            # Store into DataFrame
            data = {
                'Length_X': [length_x],
                'Width_Y': [width_y],
                'Height_Z': [height_z]
            }
    
            df = pd.DataFrame(data)
            print(df)
    
     

    Last edit: PeterPetersen 2023-09-15

Log in to post a comment.