Better algorithm for creating pitched roof (probably)?

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Better algorithm for creating pitched roof (probably)?

Post by ebrahim raeyat »

I worked a little with FreeCAD Roof command, but it has some unexpected behavior in some roofs. I searched a little about another algorithms and found that there is a straight skeleton algorithm and also a library with python for this goal. I hack it to draw some complicate roofs and I think it can recognize all pieces of roof correctly,
the input is polygon point coordinates and the output is original shape coordinate, edge points in two separate parameters: sinks and source, and heights. It assumes 45 degree for angle. This is some output:
roof1.png
roof1.png (8.65 KiB) Viewed 4324 times
roof2.png
roof2.png (11.04 KiB) Viewed 4324 times
Then to create 3D we can use two options:

1- using the height of skeleton library that give us, but with some hack, but it needs some modification. Or it is better to use generalfuse command to unify some edges and then apply height, I examined it, but not succeed:
roof3.png
roof3.png (23.33 KiB) Viewed 4324 times
2- First use slice command in Part WB to identify 2D pieces and then project this pieces on the plate with appropriate slop:
WhatsApp Image 2020-10-20 at 1.38.15 AM.jpeg
WhatsApp Image 2020-10-20 at 1.38.15 AM.jpeg (57.61 KiB) Viewed 4324 times
Although this way is only for unique angle for all pieces of roof. Thanks
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Better algorithm for creating pitched roof (probably)?

Post by Roy_043 »

ebrahim raeyat wrote: Wed Oct 21, 2020 10:03 am I worked a little with FreeCAD Roof command, but it has some unexpected behavior in some roofs.
The Arch_Roof algorithm has some obvious limitations. I have quite recently improved the code, fixing several bugs and making the code more robust. My PR was merged on October 12 2020. So please check if you are using that version.

https://github.com/FreeCAD/FreeCAD/pull ... r498712220
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Better algorithm for creating pitched roof (probably)?

Post by ebrahim raeyat »

Roy_043 wrote: Wed Oct 21, 2020 12:54 pm
ebrahim raeyat wrote: Wed Oct 21, 2020 10:03 am I worked a little with FreeCAD Roof command, but it has some unexpected behavior in some roofs.
The Arch_Roof algorithm has some obvious limitations. I have quite recently improved the code, fixing several bugs and making the code more robust. My PR was merged on October 12 2020. So please check if you are using that version.

https://github.com/FreeCAD/FreeCAD/pull ... r498712220
Thanks @Roy_043. I had been pulled the last version, but after reading wiki roof command and source code, I can't figure out how can I draw pitched roof for complex (a little!) shapes automatically. For example for above sketch. But I searched and find this library for this purpose:

https://github.com/Botffy/polyskel
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Better algorithm for creating pitched roof (probably)?

Post by ebrahim raeyat »

Ah, my FreeCAD version:

Code: Select all

OS: Ubuntu 20.04.1 LTS (KDE/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22783 (Git)
Build type: Unknown
Branch: master
Hash: 16ec7c3612f7b8b28292b107958db110dfef82d0
Python version: 3.8.5
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.3.0
Locale: English/United States (en_US)
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Better algorithm for creating pitched roof (probably)?

Post by Roy_043 »

As explained in one of my comments in the PR, one of the limitations of the current algorithm is that only direct neighbors are checked when determining the outline of a roof segment. On the other hand the code does have certain features: variable overhangs and runs, and variable angles.

Does the code found at https://github.com/Botffy/polyskel support variable angles?
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Better algorithm for creating pitched roof (probably)?

Post by ebrahim raeyat »

Roy_043 wrote: Thu Oct 22, 2020 3:16 pm As explained in one of my comments in the PR, one of the limitations of the current algorithm is that only direct neighbors are checked when determining the outline of a roof segment. On the other hand the code does have certain features: variable overhangs and runs, and variable angles.

Does the code found at https://github.com/Botffy/polyskel support variable angles?

No, it does not support variable angles as I know, but there is a c ++ library that support variable angles with weighted parameter, this is paper that explain the algorithm:

https://geder.at/research/2020/2020%20- ... iences.pdf

and these are source codes !:
https://github.com/cgalab/monos
https://github.com/cgalab/surfer2
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Better algorithm for creating pitched roof (probably)?

Post by Roy_043 »

Thanks for those links. I'll try to look at them, but this stuff may prove to be over my head.

Keep in mind that the current algorithm supports gables, and roof segments with different angles based on consecutive parallel edges. Also the roof segments need not connect at the top. In other words: there does not have to be an enclosed space under the roof.
But the algorithms you refer to may provide inspiration for Arch_Roof and perhaps also for Arch_Space (which also works by intersecting planes).

Interestingly the ACIS geometric kernel, used by AutoCAD, BricsCAD etc., can create the complex roofs in your first post with a single extrude operation.
Attachments
Complex_Roof_ACIS_Extrude.png
Complex_Roof_ACIS_Extrude.png (76.61 KiB) Viewed 4118 times
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Better algorithm for creating pitched roof (probably)?

Post by ebrahim raeyat »

Roy_043 wrote: Fri Oct 23, 2020 7:36 am Thanks for those links. I'll try to look at them, but this stuff may prove to be over my head.

Keep in mind that the current algorithm supports gables, and roof segments with different angles based on consecutive parallel edges. Also the roof segments need not connect at the top. In other words: there does not have to be an enclosed space under the roof.
But the algorithms you refer to may provide inspiration for Arch_Roof and perhaps also for Arch_Space (which also works by intersecting planes).

Interestingly the ACIS geometric kernel, used by AutoCAD, BricsCAD etc., can create the complex roofs in your first post with a single extrude operation.
Thanks for your quick replies. I know the Arch-roof command has more options for drawing, but my goal for announcing this is if we could add a command like you mentioned that exist in BricsCAD etc.

But until that, I have only one question:
how can I find the perpendicular distance from a point to line in FreeCAD. I searched a lot and found that exist a Part measure tools, but it gets the shortest distance and some extra vector:
dist1.png
dist1.png (6.94 KiB) Viewed 4079 times
Then I used direct formula for calculating distance from a point to line, but it gets me only the distance of the point from the origin axis, not line!

https://en.wikipedia.org/wiki/Distance_ ... _to_a_line

If I could obtain the distance, I can obtain the height of all points in each piece that I obtained from Part slice command from the edge of polygon.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Better algorithm for creating pitched roof (probably)?

Post by Roy_043 »

Draft has several geometry functions:

Code: Select all

import draftgeoutils

draftgeoutils.geometry.findDistance(App.Vector(), [App.Vector(1,0,0), App.Vector(0,1,0)])

edge = App.ActiveDocument.Line.Shape.Edges[0]
draftgeoutils.geometry.findDistance(App.Vector(), edge)
To do this manually you can use the Draft_Dimension command and the Draft_Snap_Perpendicular snap.
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Better algorithm for creating pitched roof (probably)?

Post by ebrahim raeyat »

Roy_043 wrote: Fri Oct 23, 2020 1:41 pm Draft has several geometry functions:

Code: Select all

import draftgeoutils

draftgeoutils.geometry.findDistance(App.Vector(), [App.Vector(1,0,0), App.Vector(0,1,0)])

edge = App.ActiveDocument.Line.Shape.Edges[0]
draftgeoutils.geometry.findDistance(App.Vector(), edge)
To do this manually you can use the Draft_Dimension command and the Draft_Snap_Perpendicular snap.
Thanks a lot. Finally, for constant angles:
roof4.png
roof4.png (12.74 KiB) Viewed 4017 times
roof5.png
roof5.png (18.85 KiB) Viewed 4017 times
Post Reply