Converting DXF to IFC format

I am currently working on application that convert DXF files into IFC, using NetDXF library to get data from DXF then I use Xbim library to create the IFC file.
As shown in these screenshots, I use this function to get center point , X_Dimension and Y_Dimension for a rectangle then I use this data to create my IFC file and it works well for rectangles that are not Inclined.
My question is how to get center point , X_Dimension and Y_Dimension for inclined rectangles correctly, but you have to consider that the sequence of the vertexes may differ each time as the user may draw rectangle in clockwise direction , anticlockwise or even he may draw lines then join this lines to make the rectangle.
I hope my question is clear enough.
Thanks in advance.
Snap 2021-06-04 at 03.37.42



This does not seem like an IFC question, but rather a general geometry question using open source libraries. Perhaps Community.OSArch.org is better suited to questions like this in the future?

Given a soup of vertices, pick any arbitrary vertex, then compute and sort the distance from that vertex to the three remaining vertexes. The furthest distance must be the diagonal. The remainder is your X and Y. Hope that helps.

In addition, there is an experimental IfcOpenShell DXF2IFC converter here: IfcOpenShell/dxf2ifc.py at v0.6.0 · IfcOpenShell/IfcOpenShell · GitHub - have you considered collaborating?

1 Like

I appreciate your help so much @Moult and I really didn’t hear about community.osarch.org before.

I will have a look at your DXF2IFC converter, but unfortunately I just know the basics of Python right now.

I will try to implement your Algorithm, I believe it will help me.
Thank you for your time.

Maybe I am wrong, but isn’t the center of an inclined rectangle the same as a the center of the axis-aligned representation? It only depends on the parent transform. So the local center itself shouldn’t change. As long you don’t need a weighted barycenter representation, the center itself is computable by averaging the coordinates of all points in any order.

@Bernold.K you are correct, but I believe his question was dealing with DXFs, where perhaps there is just a “soup” of vertexes and edges, and perhaps he needs to derive the parent transform.

@Bernold.K the problem was I had a “soup” of vertexes, so I used the Algorithm recommended by @Moult and it woks well.

“Soup” meant “any order” (or unordered) for me. If it works it’s fine.