Discussion:
[OpenSCAD] $fn, $fa and $fs
Lucas Vinicius Hartmann
2016-07-18 14:48:30 UTC
Permalink
I know the idea behind each of them, but how do they interact? Suppose I
specify all three of them and then draw a cylinder of radius r, how does
OpenSCAD decide how many sides to make it with?

In other words, it is almost always impossible to have exactly $fn sides,
$fs long and covering $fa degrees each... How is this conflict solved?
Ronaldo Persiano
2016-07-18 15:38:34 UTC
Permalink
$fn, $fa, $fs are special variables reported in the manual page
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#.24fa.2C_.24fs_and_.24fn
where an algorithm shows how a final value is chosen.
Post by Lucas Vinicius Hartmann
I know the idea behind each of them, but how do they interact? Suppose I
specify all three of them and then draw a cylinder of radius r, how does
OpenSCAD decide how many sides to make it with?
In other words, it is almost always impossible to have exactly $fn sides,
$fs long and covering $fa degrees each... How is this conflict solved?
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Lucas Vinicius Hartmann
2016-07-18 16:20:16 UTC
Permalink
In english that code reads:

If $fn is defined then $fn fragments.
otherwise the *least number of fragments to satisfy EITHER $fn OR $fa*.

That's what I wanted, thanks. :-)

--
Lucas Vinicius Hartmann

Dizem que se você rodar o CD do Windows ao contrário ele mostra uma
mensagem demoníaca... Mas isso nem é o pior, se você rodar ele normal ele
instala o Windows!
Post by Ronaldo Persiano
$fn, $fa, $fs are special variables reported in the manual page
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#.24fa.2C_.24fs_and_.24fn
where an algorithm shows how a final value is chosen.
2016-07-18 11:48 GMT-03:00 Lucas Vinicius Hartmann <
Post by Lucas Vinicius Hartmann
I know the idea behind each of them, but how do they interact? Suppose I
specify all three of them and then draw a cylinder of radius r, how does
OpenSCAD decide how many sides to make it with?
In other words, it is almost always impossible to have exactly $fn sides,
$fs long and covering $fa degrees each... How is this conflict solved?
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
MichaelAtOz
2016-07-18 22:45:27 UTC
Permalink
(int)
ceil( // round it up.
fmax(
fmin( // Use the min of the following two
segments
360.0 / fa // 360/angle= number of segments
, r*2*M_PI / fs) // 2pi*r = circumference/fs= number of segments
, 5) // this means 5 is the minimum if above is
<5
)
-----
Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
--
View this message in context: http://forum.openscad.org/fn-fa-and-fs-tp17932p17936.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Lucas Vinicius Hartmann
2016-07-19 16:36:53 UTC
Permalink
Other words, given that both conditions yield more than 5 fragments:

- Fragments will never be less than $fa degrees, no matter how large the
circle.

- Fragments will never be shorter that $fs, no matter how small the circle.

I guess if would be interesting if that function could be exposed to the
openscad language, so we would be able to override it should we feel the
need to.
(int)
ceil( // round it up.
fmax(
fmin( // Use the min of the following two
segments
360.0 / fa // 360/angle= number of segments
, r*2*M_PI / fs) // 2pi*r = circumference/fs= number of
segments
, 5) // this means 5 is the minimum if above
is
<5
)
-----
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the
Public Domain; to the extent possible under law, I have waived all
copyright and related or neighbouring rights to this work. Obviously
inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it!
http://www.ourfairdeal.org/ time is running out!
--
http://forum.openscad.org/fn-fa-and-fs-tp17932p17936.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
MichaelAtOz
2016-07-20 05:15:32 UTC
Permalink
Post by Lucas Vinicius Hartmann
I guess if would be interesting if that function could be exposed to the
openscad language, so we would be able to override it should we feel the
need to.
You just set $fn to however you want to calculate it. You can read $fa $fs
variables (& $fn) just like normal variables.



-----
Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
--
View this message in context: http://forum.openscad.org/fn-fa-and-fs-tp17932p17946.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Lucas Vinicius Hartmann
2016-07-20 11:29:23 UTC
Permalink
That works, but you have to do it for every single circle because you can
not read radius.

Or I can create new modules, mycircle, mycylinder, mysphere, and do the
math any way I want. Yeah, this will work.

Thanks.
Post by MichaelAtOz
Post by Lucas Vinicius Hartmann
I guess if would be interesting if that function could be exposed to the
openscad language, so we would be able to override it should we feel the
need to.
You just set $fn to however you want to calculate it. You can read $fa $fs
variables (& $fn) just like normal variables.
-----
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the
Public Domain; to the extent possible under law, I have waived all
copyright and related or neighbouring rights to this work. Obviously
inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it!
http://www.ourfairdeal.org/ time is running out!
--
http://forum.openscad.org/fn-fa-and-fs-tp17932p17946.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Continue reading on narkive:
Loading...