I have an IFC file of a 3D building model (BIM) split into constituent physical objects and I have properties that I want to assign to the correct object. The properties come with a location: they are scalar values associated with a point in 3D space. If I have a point P1 = (x1, y1, z1), how can I determine whether this point is located within, say, the door, or the wall next to the door (or neither, in the air)?
I see two options but couldn't decipher the Xbim/IFC documentation to get anywhere with either approach:
- Look to the location P1 in the BIM and ask: which, if any, object occupies this point in space?
- Look through each object in the BIM and ask: does this object extend around P1, based on its shape and global position?
As an extra challenge, I might eventually be distributing tens of thousands of properties in a very large BIM, so a low complexity algorithm is preferred.
Essentially you're looking at a Collision detection algorithm. This is quite a complex topic...
For efficiency you often build an OctTree of the scene - Xbim has an implementation here https://github.com/xBimTeam/XbimGeometry/blob/master/Xbim.ModelGeometry.Scene/XbimOctree.cs
.. which you can use.
There's some high-level example code of using Bounding boxes and Octrees to calculate if two products intersect or contain one another etc, which may get you some of the way at https://github.com/xBimTeam/XbimAnalysis/tree/develop/Xbim.Analysis/Spatial
.. but you'd need to adjust for your specific scenario. Also note that testing against a bounding box (or a hit box) will give some false positives if the geometry is irregular (e.g. the bounding box of a chair will have a much greater volume that its true geometry), so you may need to have a more refined collision detection once you have a candidate hit.