Does anybody know the calculation openscad uses for the number of segments
on an arc of angle theta as a function of $fn? Exactly what kind of
rounding is used?
At least in DxfData:
n = static_cast<int>(ceil(n * arc_angle / 360));
where n comes from
int n = Calc::get_fragments_from_r(radius, fn, fs, fa);
which returns $fn so long as it's at least 3: https://github.com/openscad/openscad/blob/master/src%2Futils%2Fcalc.cc#L47
https://github.com/openscad/openscad/blob/master/src%2Fio%2FDxfData.cc#L205
Sorry for non-permalinks.
On August 21, 2025 8:18:44 AM EDT, Adrian Mariano via Discuss discuss@lists.openscad.org wrote:
Does anybody know the calculation openscad uses for the number of segments
on an arc of angle theta as a function of $fn? Exactly what kind of
rounding is used?
Thanks. The possibility of rounding error exists in the computation.
Someone observed in BOSL2 that offset behaved irregularly. The existing
calculation does not match openscad but even with it fixed if I offset a
regular n gon with $fn = n I get rounding errors and sometimes the ceil
rounds up giving an extra facet. Openscad seems to avoid this somehow and
consistently produces just a single facet.
On Thu, Aug 21, 2025 at 09:43 Cory Cross via Discuss <
discuss@lists.openscad.org> wrote:
At least in DxfData:
n = static_cast<int>(ceil(n * arc_angle / 360));
where n comes from
int n = Calc::get_fragments_from_r(radius, fn, fs, fa);
which returns $fn so long as it's at least 3: <
https://github.com/openscad/openscad/blob/master/src%2Futils%2Fcalc.cc#L47
Sorry for non-permalinks.
On August 21, 2025 8:18:44 AM EDT, Adrian Mariano via Discuss <
discuss@lists.openscad.org> wrote:
Does anybody know the calculation openscad uses for the number of
segments on an arc of angle theta as a function of $fn? Exactly what kind
of rounding is used?
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
In C++, OpenSCAD converts n to int first before doing the arc angle calculation. That may introduce a tiny difference, as if you do the same calculation in OpenSCAD, it’s kept as double all the way. Not sure if that’s the root cause though..
-Marius
On Aug 21, 2025, at 10:22, Adrian Mariano via Discuss discuss@lists.openscad.org wrote:
Thanks. The possibility of rounding error exists in the computation. Someone observed in BOSL2 that offset behaved irregularly. The existing calculation does not match openscad but even with it fixed if I offset a regular n gon with $fn = n I get rounding errors and sometimes the ceil rounds up giving an extra facet. Openscad seems to avoid this somehow and consistently produces just a single facet.
On Thu, Aug 21, 2025 at 09:43 Cory Cross via Discuss <discuss@lists.openscad.org mailto:discuss@lists.openscad.org> wrote:
At least in DxfData:
n = static_cast<int>(ceil(n * arc_angle / 360));
where n comes from
int n = Calc::get_fragments_from_r(radius, fn, fs, fa);
which returns $fn so long as it's at least 3: https://github.com/openscad/openscad/blob/master/src%2Futils%2Fcalc.cc#L47
https://github.com/openscad/openscad/blob/master/src%2Fio%2FDxfData.cc#L205
Sorry for non-permalinks.
On August 21, 2025 8:18:44 AM EDT, Adrian Mariano via Discuss <discuss@lists.openscad.org mailto:discuss@lists.openscad.org> wrote:
Does anybody know the calculation openscad uses for the number of segments on an arc of angle theta as a function of $fn? Exactly what kind of rounding is used?
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org mailto:discuss-leave@lists.openscad.org_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org