better than $fn: get $fs working, a tutorial

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

better than $fn: get $fs working, a tutorial

Baxsie
I had never been able to get $fs to make a difference. As a work-around had put several different $fn statements spread through the code, depending on the diameter of the object. After I finally slowed down enough to look at the problem, I came up with this snippet, which you just need to put once at the top of the file.

//Disable $fn and $fa, do not change these
$fn=0;
$fa=0.01;

//Use only $fs to control the number of facets globally.
// fine ~ 0.1  coarse ~ 0.5
$fs=0.1;

This approach keeps large arcs nice and smooth, while limiting the number of facets on small objects. You only ever have to change the $fs line to go between "quick preview" and "fine render for build" modes.

The only other time $fn (or $fs or $fa) should show up is if you are using $fn=6 to force a hexagon.

Reply | Threaded
Open this post in threaded view
|

Re: better than $fn: get $fs working, a tutorial

Whosawhatsis
I have had trouble with it in the past too, but it seems to work as
expected in the most recent release ONLY if you set a $fa to a very
small value like 0.01 also. Which release are you using?

On Mon, Jul 25, 2011 at 11:25 AM, Brent Crosby <[hidden email]> wrote:

> I had never been able to get $fs to make a difference. As a work-around had
> put several different $fn statements spread through the code, depending on
> the diameter of the object. After I finally slowed down enough to look at
> the problem, I came up with this snippet, which you just need to put once at
> the top of the file.
> //Disable $fn and $fa, do not change these
> $fn=0;
> $fa=0.01;
> //ref:
> http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features
> //Use only $fs to control the number of facets globally.
> // fine ~ 0.1  coarse ~ 0.5
> $fs=0.1;
> This approach keeps large arcs nice and smooth, while limiting the number of
> facets on small objects. You only ever have to change the $fs line to go
> between "quick preview" and "fine render for build" modes.
> The only other time $fn (or $fs or $fa) should show up is if you are using
> $fn=6 to force a hexagon.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>
>

Reply | Threaded
Open this post in threaded view
|

Re: better than $fn: get $fs working, a tutorial

Giles Bathgate-2
On 25 July 2011 21:51, Whosawhatsis <[hidden email]> wrote:
> I have had trouble with it in the past too, but it seems to work as
> expected in the most recent release ONLY if you set a $fa to a very
> small value like 0.01 also. Which release are you using?

The code on the wiki is slightly inaccurate in commit
https://github.com/openscad/openscad/commit/3487678ca142fd9c3a9ff257d927a4f9fa2a7bc4
the line

if (r < GRID_FINE) return 0;

was added. However this was done a very long time ago (2010-01-30) and
hasn't changed recently thus the complete code to date is:

/*!
        Returns the number of subdivision of a whole circle, given radius and
        the three special variables $fn, $fs and $fa
*/
int get_fragments_from_r(double r, double fn, double fs, double fa)
{
        if (r < GRID_FINE) return 0;
        if (fn > 0.0)
                return (int)fn;
        return (int)ceil(fmax(fmin(360.0 / fa, r*M_PI / fs), 5));
}

Maybe this provides some enlightenment.

The wiki needs updating:
http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features

Regards

Giles.

Reply | Threaded
Open this post in threaded view
|

Re: better than $fn: get $fs working, a tutorial

Giles Bathgate-2
This commit might also effect something:
https://github.com/openscad/openscad/commit/496cc66cf253b805db73c4ce39fc477591f2c60e

Regards

Giles