mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-28 14:30:19 +02:00
add angle argument to segs()
This commit is contained in:
18
utility.scad
18
utility.scad
@@ -772,17 +772,21 @@ function scalar_vec3(v, dflt) =
|
|||||||
// Topics: Geometry
|
// Topics: Geometry
|
||||||
// See Also: circle(), cyl()
|
// See Also: circle(), cyl()
|
||||||
// Usage:
|
// Usage:
|
||||||
// sides = segs(r);
|
// sides = segs(r, [angle]);
|
||||||
// Description:
|
// Description:
|
||||||
// Calculate the standard number of sides OpenSCAD would give a circle based on `$fn`, `$fa`, and `$fs`.
|
// Calculate the standard number of sides OpenSCAD would give a circle based on `$fn`, `$fa`, and `$fs`.
|
||||||
|
// If angle is given, calculate for an arc of the given angle.
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// r = Radius of circle to get the number of segments for.
|
// r = Radius of circle/arc to get the number of segments for.
|
||||||
|
// angle = Angle of arc to get the get the number of segments for.
|
||||||
// Example:
|
// Example:
|
||||||
// $fn=12; sides=segs(10); // Returns: 12
|
// $fn=12; sides=segs(10); // Returns: 12
|
||||||
// $fa=2; $fs=3; sides=segs(10); // Returns: 21
|
// $fa=2; $fs=3; sides=segs(10); // Returns: 21
|
||||||
function segs(r) =
|
// $fa=2; $fs=3; sides=segs(10,180); // Returns: 11
|
||||||
$fn>0? ($fn>3? $fn : 3) :
|
function segs(r,angle) =
|
||||||
let( r = is_finite(r)? r : 0 )
|
is_def(angle) ? ceil(segs(r)*abs(angle)/360-2e-15) // 2e-15 needed in case angle is slightly large due to rounding error
|
||||||
|
: $fn>0? ($fn>3? $fn : 3)
|
||||||
|
: let( r = is_finite(r)? r : 0 )
|
||||||
ceil(max(5, min(360/$fa, abs(r)*2*PI/$fs)));
|
ceil(max(5, min(360/$fa, abs(r)*2*PI/$fs)));
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user