LM
Leonard Martin Struttmann
Mon, Jun 29, 2026 1:28 PM
Dear OpenSCAD,
Due to the way that OpenSCAD creates spheres, it seems that the
bounding-box dimensions of the sphere are less than the diameter of the
sphere in at least two directions. This is especially apparent when using
low values for $fn during development. This can be visualized by using:
%cube( [ 20, 20, 20 ], center=true);
sphere( 10 );
Is there a way to tell sphere() to avoid this by creating vertices along
all three axes, regardless of the $fn value?
Currently, my solution is:
module MySphere( r=10 )
{
hull()
{
sphere( 10 );
rotate_extrude(angle = 360, convexity = 2, $fn=4)
polygon( [[ 0,10], [10,0], [0,-10]]);
}
}
Is there a better way to do this?
Thanks!
Len
Dear OpenSCAD,
Due to the way that OpenSCAD creates spheres, it seems that the
bounding-box dimensions of the sphere are less than the diameter of the
sphere in at least two directions. This is especially apparent when using
low values for $fn during development. This can be visualized by using:
%cube( [ 20, 20, 20 ], center=true);
sphere( 10 );
Is there a way to tell sphere() to avoid this by creating vertices along
all three axes, regardless of the $fn value?
Currently, my solution is:
module MySphere( r=10 )
{
hull()
{
sphere( 10 );
rotate_extrude(angle = 360, convexity = 2, $fn=4)
polygon( [[ 0,10], [10,0], [0,-10]]);
}
}
Is there a better way to do this?
Thanks!
Len
AM
Adrian Mariano
Mon, Jun 29, 2026 4:26 PM
Use BOSL2 spheroid() with the “octa” style.
On Mon, Jun 29, 2026 at 09:28 Leonard Martin Struttmann via Discuss <
discuss@lists.openscad.org> wrote:
Dear OpenSCAD,
Due to the way that OpenSCAD creates spheres, it seems that the
bounding-box dimensions of the sphere are less than the diameter of the
sphere in at least two directions. This is especially apparent when using
low values for $fn during development. This can be visualized by using:
%cube( [ 20, 20, 20 ], center=true);
sphere( 10 );
Is there a way to tell sphere() to avoid this by creating vertices along
all three axes, regardless of the $fn value?
Currently, my solution is:
module MySphere( r=10 )
{
hull()
{
sphere( 10 );
rotate_extrude(angle = 360, convexity = 2, $fn=4)
polygon( [[ 0,10], [10,0], [0,-10]]);
}
}
Is there a better way to do this?
Thanks!
Len
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Use BOSL2 spheroid() with the “octa” style.
On Mon, Jun 29, 2026 at 09:28 Leonard Martin Struttmann via Discuss <
discuss@lists.openscad.org> wrote:
> Dear OpenSCAD,
>
> Due to the way that OpenSCAD creates spheres, it seems that the
> bounding-box dimensions of the sphere are less than the diameter of the
> sphere in at least two directions. This is especially apparent when using
> low values for $fn during development. This can be visualized by using:
>
> %cube( [ 20, 20, 20 ], center=true);
>
> sphere( 10 );
>
> Is there a way to tell sphere() to avoid this by creating vertices along
> all three axes, regardless of the $fn value?
>
> Currently, my solution is:
>
> module MySphere( r=10 )
>
> {
>
> hull()
>
> {
>
> sphere( 10 );
>
> rotate_extrude(angle = 360, convexity = 2, $fn=4)
>
> polygon( [[ 0,10], [10,0], [0,-10]]);
>
> }
>
> }
>
> Is there a better way to do this?
>
> Thanks!
>
> Len
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
RW
Raymond West
Mon, Jun 29, 2026 9:19 PM
Hi, Leonard,
Your solution, just pushes points out at the appropriate places to make
the sphere look like it fits the box.
I slightly altered your code to clearly show that.
module MySphere( r=10 )
{
hull()
{
% sphere( 10 ,$fn=8);
rotate_extrude(angle = 360, convexity = 2, $fn=4)
polygon( [[ 0,10], [10,0], [0,-10]]);
}
}
MySphere();
It is more interesting/simpler to look at circles. If the $fn is a
multiple of four, it always fits. I would guess, maybe, that there are
values for spheres that always fit, but maybe not, but maybe in 2
dimensions only. It is all an approximation, anyway.
.
On 29/06/2026 14:28, Leonard Martin Struttmann via Discuss wrote:
module MySphere( r=10 )
{
hull()
{
sphere( 10 );
rotate_extrude(angle = 360, convexity = 2, $fn=4)
polygon( [[ 0,10], [10,0], [0,-10]]);
}
}
Is there a better way to do this?
Than
Hi, Leonard,
Your solution, just pushes points out at the appropriate places to make
the sphere look like it fits the box.
I slightly altered your code to clearly show that.
module MySphere( r=10 )
{
hull()
{
% sphere( 10 ,$fn=8);
rotate_extrude(angle = 360, convexity = 2, $fn=4)
polygon( [[ 0,10], [10,0], [0,-10]]);
}
}
MySphere();
It is more interesting/simpler to look at circles. If the $fn is a
multiple of four, it always fits. I would guess, maybe, that there are
values for spheres that always fit, but maybe not, but maybe in 2
dimensions only. It is all an approximation, anyway.
.
On 29/06/2026 14:28, Leonard Martin Struttmann via Discuss wrote:
>
> module MySphere( r=10 )
>
> {
>
> hull()
>
> {
>
> sphere( 10 );
>
>
> rotate_extrude(angle = 360, convexity = 2, $fn=4)
>
> polygon( [[ 0,10], [10,0], [0,-10]]);
>
> }
>
> }
>
>
> Is there a better way to do this?
>
>
> Than
>
LM
Leonard Martin Struttmann
Mon, Jun 29, 2026 11:20 PM
Raymond,
*Your solution, just pushes points out at the appropriate places to make
the sphere look like it fits the box. *
Yes, I agree. However, for my current design, that is sufficient. I need
an approximate sphere and for there to be vertices on each of the axes.
Using $fn=48 for the sphere(), what I normally render at, the
differences are minimal.
*If the $fn is a multiple of four, it always fits. *
Yes, I could certainly use that constraint. But, that only works for
circles. That still leaves the flat spots at the poles of sphere.
Len
Raymond,
*Your solution, just pushes points out at the appropriate places to make
the sphere look like it fits the box. *
Yes, I agree. However, for my current design, that is sufficient. I need
an approximate sphere and for there to be vertices on each of the axes.
Using $fn=48 for the sphere(), what I normally render at, the
differences are minimal.
*If the $fn is a multiple of four, it always fits. *
Yes, I could certainly use that constraint. But, that only works for
circles. That still leaves the flat spots at the poles of sphere.
Len
AM
Adrian Mariano
Mon, Jun 29, 2026 11:31 PM
The right solution is to use the octahedron based sphere. If you do that,
then for $fn=4, it always works. The octahedron based sphere is also much
more symmetric and doesn't have extra triangles at poles somewhere so it's
more spherical for the same triangle count. You can go implement it
yourself if you're a masochist. You can get it from BOSL2. You can, I
think, find BOSL2-free code in the discussion of an openscad issue about
this very problem, or actually on the linked PR, where there was a lengthy
discussion about how to implement this. It's not the simplest thing to
implement. There is some subtlety in exactly how the triangles of the
octahedron get subdivided.
https://github.com/openscad/openscad/issues/1983
[image: image.png]
On Mon, Jun 29, 2026 at 7:21 PM Leonard Martin Struttmann via Discuss <
discuss@lists.openscad.org> wrote:
Raymond,
*Your solution, just pushes points out at the appropriate places to make
the sphere look like it fits the box. *
Yes, I agree. However, for my current design, that is sufficient. I need
an approximate sphere and for there to be vertices on each of the axes.
Using $fn=48 for the sphere(), what I normally render at, the
differences are minimal.
*If the $fn is a multiple of four, it always fits. *
Yes, I could certainly use that constraint. But, that only works for
circles. That still leaves the flat spots at the poles of sphere.
Len
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
The right solution is to use the octahedron based sphere. If you do that,
then for $fn=4, it always works. The octahedron based sphere is also much
more symmetric and doesn't have extra triangles at poles somewhere so it's
more spherical for the same triangle count. You can go implement it
yourself if you're a masochist. You can get it from BOSL2. You can, I
think, find BOSL2-free code in the discussion of an openscad issue about
this very problem, or actually on the linked PR, where there was a lengthy
discussion about how to implement this. It's not the simplest thing to
implement. There is some subtlety in exactly how the triangles of the
octahedron get subdivided.
https://github.com/openscad/openscad/issues/1983
[image: image.png]
On Mon, Jun 29, 2026 at 7:21 PM Leonard Martin Struttmann via Discuss <
discuss@lists.openscad.org> wrote:
> Raymond,
>
> *Your solution, just pushes points out at the appropriate places to make
> the sphere look like it fits the box. *
>
> Yes, I agree. However, for my current design, that is sufficient. I need
> an approximate sphere and for there to be vertices on each of the axes.
> Using $fn=48 for the sphere(), what I normally render at, the
> differences are minimal.
>
> *If the $fn is a multiple of four, it always fits. *
>
> Yes, I could certainly use that constraint. But, that only works for
> circles. That still leaves the flat spots at the poles of sphere.
>
> Len
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
LM
Leonard Martin Struttmann
Tue, Jun 30, 2026 2:06 AM
Wow! The octahedron based sphere would be complicated. I think that I’ll
try something simpler:
module MYsphere( r=1, d = undef)
{
function MYfn(f) = floor((f + 2) / 4) * 4;
F = MYfn($fn);
R = is_undef(d) ? r : d / 2;
p = [ for (a=[-90:180/F:90]) polar_to_rectangular([ R, a ] ) ];
rotate_extrude(angle = 360, convexity = 10, $fn=F )
polygon( p );
}
Len
For $fn = 24
[image: image.png]
Wow! The octahedron based sphere would be complicated. I think that I’ll
try something simpler:
module MYsphere( r=1, d = undef)
{
function MYfn(f) = floor((f + 2) / 4) * 4;
F = MYfn($fn);
R = is_undef(d) ? r : d / 2;
p = [ for (a=[-90:180/F:90]) polar_to_rectangular([ R, a ] ) ];
rotate_extrude(angle = 360, convexity = 10, $fn=F )
polygon( p );
}
Len
For $fn = 24
[image: image.png]
JB
Jordan Brown
Tue, Jun 30, 2026 3:49 AM
On 6/29/2026 7:06 PM, Leonard Martin Struttmann via Discuss wrote:
Wow! The octahedron based sphere would be complicated. I think that
I’ll try something simpler:
But they are much prettier.
I believe my PR implements the same algorithm that BOSL2 uses. The only
reason that I think it should perhaps be built in is that I think we
should eventually migrate over to it (or something similar) as the default.
Here's a fairly simple scheme that gives you spheres with vertexes on
the theoretical bounding box, for $fn (or the equivalent result from
$fa/$fs or $fe) being a multiple of 4. It takes advantage of the fact
that a circle (with $fn a multiple of 4) does put vertexes on the
axes. (No, I don't know why spheres don't do it that way.)
$fn=8;
module halfcircle(r, d) {
r = !is_undef(r)
? r
: !is_undef(d)
? d/2
: 1;
difference() {
circle(r=r);
translate([-(r+1), -(r+1)])
square([r+1, r*2+2]);
}
}
rotate_extrude() halfcircle();
On 6/29/2026 7:06 PM, Leonard Martin Struttmann via Discuss wrote:
>
> Wow! The octahedron based sphere would be complicated. I think that
> I’ll try something simpler:
>
>
But they are *much* prettier.
I believe my PR implements the same algorithm that BOSL2 uses. The only
reason that I think it should perhaps be built in is that I think we
should eventually migrate over to it (or something similar) as the default.
Here's a fairly simple scheme that gives you spheres with vertexes on
the theoretical bounding box, for $fn (or the equivalent result from
$fa/$fs or $fe) being a multiple of 4. It takes advantage of the fact
that a circle (with $fn a multiple of 4) *does* put vertexes on the
axes. (No, I don't know why spheres don't do it that way.)
$fn=8;
module halfcircle(r, d) {
r = !is_undef(r)
? r
: !is_undef(d)
? d/2
: 1;
difference() {
circle(r=r);
translate([-(r+1), -(r+1)])
square([r+1, r*2+2]);
}
}
rotate_extrude() halfcircle();
SP
Sanjeev Prabhakar
Tue, Jun 30, 2026 6:50 AM
I have read the first few pages of this cube sphere and the idea is that
you create a cube with multiple points centered at origin.
Then when you normalise all the points of that cube and multiply by some
distance, say 'r', it will create a sphere with radius 'r'.
This I think is a good idea and should not be very difficult to implement.
On Tue, 30 Jun 2026 at 07:36, Leonard Martin Struttmann via Discuss <
discuss@lists.openscad.org> wrote:
Wow! The octahedron based sphere would be complicated. I think that
I’ll try something simpler:
module MYsphere( r=1, d = undef)
{
function MYfn(f) = floor((f + 2) / 4) * 4;
F = MYfn($fn);
R = is_undef(d) ? r : d / 2;
p = [ for (a=[-90:180/F:90]) polar_to_rectangular([ R, a ] ) ];
rotate_extrude(angle = 360, convexity = 10, $fn=F )
polygon( p );
}
Len
For $fn = 24
[image: image.png]
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I have read the first few pages of this cube sphere and the idea is that
you create a cube with multiple points centered at origin.
Then when you normalise all the points of that cube and multiply by some
distance, say 'r', it will create a sphere with radius 'r'.
This I think is a good idea and should not be very difficult to implement.
On Tue, 30 Jun 2026 at 07:36, Leonard Martin Struttmann via Discuss <
discuss@lists.openscad.org> wrote:
> Wow! The octahedron based sphere would be complicated. I think that
> I’ll try something simpler:
>
> module MYsphere( r=1, d = undef)
>
> {
>
> function MYfn(f) = floor((f + 2) / 4) * 4;
>
> F = MYfn($fn);
>
> R = is_undef(d) ? r : d / 2;
>
> p = [ for (a=[-90:180/F:90]) polar_to_rectangular([ R, a ] ) ];
>
> rotate_extrude(angle = 360, convexity = 10, $fn=F )
>
> polygon( p );
>
> }
>
> Len
>
> For $fn = 24
> [image: image.png]
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
SP
Sanjeev Prabhakar
Tue, Jun 30, 2026 7:56 AM
[image: Screenshot 2026-06-30 at 1.23.43 PM.png][image: Screenshot
2026-06-30 at 1.24.44 PM.png]
On Tue, 30 Jun 2026 at 12:20, Sanjeev Prabhakar sprabhakar2006@gmail.com
wrote:
I have read the first few pages of this cube sphere and the idea is that
you create a cube with multiple points centered at origin.
Then when you normalise all the points of that cube and multiply by some
distance, say 'r', it will create a sphere with radius 'r'.
This I think is a good idea and should not be very difficult to implement.
On Tue, 30 Jun 2026 at 07:36, Leonard Martin Struttmann via Discuss <
discuss@lists.openscad.org> wrote:
Wow! The octahedron based sphere would be complicated. I think that
I’ll try something simpler:
module MYsphere( r=1, d = undef)
{
function MYfn(f) = floor((f + 2) / 4) * 4;
F = MYfn($fn);
R = is_undef(d) ? r : d / 2;
p = [ for (a=[-90:180/F:90]) polar_to_rectangular([ R, a ] ) ];
rotate_extrude(angle = 360, convexity = 10, $fn=F )
polygon( p );
}
Len
For $fn = 24
[image: image.png]
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
[image: Screenshot 2026-06-30 at 1.23.43 PM.png][image: Screenshot
2026-06-30 at 1.24.44 PM.png]
On Tue, 30 Jun 2026 at 12:20, Sanjeev Prabhakar <sprabhakar2006@gmail.com>
wrote:
> I have read the first few pages of this cube sphere and the idea is that
> you create a cube with multiple points centered at origin.
> Then when you normalise all the points of that cube and multiply by some
> distance, say 'r', it will create a sphere with radius 'r'.
> This I think is a good idea and should not be very difficult to implement.
>
>
> On Tue, 30 Jun 2026 at 07:36, Leonard Martin Struttmann via Discuss <
> discuss@lists.openscad.org> wrote:
>
>> Wow! The octahedron based sphere would be complicated. I think that
>> I’ll try something simpler:
>>
>> module MYsphere( r=1, d = undef)
>>
>> {
>>
>> function MYfn(f) = floor((f + 2) / 4) * 4;
>>
>> F = MYfn($fn);
>>
>> R = is_undef(d) ? r : d / 2;
>>
>> p = [ for (a=[-90:180/F:90]) polar_to_rectangular([ R, a ] ) ];
>>
>> rotate_extrude(angle = 360, convexity = 10, $fn=F )
>>
>> polygon( p );
>>
>> }
>>
>> Len
>>
>> For $fn = 24
>> [image: image.png]
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
>
NH
nop head
Tue, Jun 30, 2026 9:18 AM
I replaced sphere with my own version that rotate_extrudes a semicircle
that has a multiple of 4 points on the original circle.
On Tue, 30 Jun 2026, 08:57 Sanjeev Prabhakar via Discuss, <
discuss@lists.openscad.org> wrote:
[image: Screenshot 2026-06-30 at 1.23.43 PM.png][image: Screenshot
2026-06-30 at 1.24.44 PM.png]
On Tue, 30 Jun 2026 at 12:20, Sanjeev Prabhakar sprabhakar2006@gmail.com
wrote:
I have read the first few pages of this cube sphere and the idea is that
you create a cube with multiple points centered at origin.
Then when you normalise all the points of that cube and multiply by some
distance, say 'r', it will create a sphere with radius 'r'.
This I think is a good idea and should not be very difficult to implement.
On Tue, 30 Jun 2026 at 07:36, Leonard Martin Struttmann via Discuss <
discuss@lists.openscad.org> wrote:
Wow! The octahedron based sphere would be complicated. I think that
I’ll try something simpler:
module MYsphere( r=1, d = undef)
{
function MYfn(f) = floor((f + 2) / 4) * 4;
F = MYfn($fn);
R = is_undef(d) ? r : d / 2;
p = [ for (a=[-90:180/F:90]) polar_to_rectangular([ R, a ] ) ];
rotate_extrude(angle = 360, convexity = 10, $fn=F )
polygon( p );
}
Len
For $fn = 24
[image: image.png]
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I replaced sphere with my own version that rotate_extrudes a semicircle
that has a multiple of 4 points on the original circle.
On Tue, 30 Jun 2026, 08:57 Sanjeev Prabhakar via Discuss, <
discuss@lists.openscad.org> wrote:
> [image: Screenshot 2026-06-30 at 1.23.43 PM.png][image: Screenshot
> 2026-06-30 at 1.24.44 PM.png]
>
>
> On Tue, 30 Jun 2026 at 12:20, Sanjeev Prabhakar <sprabhakar2006@gmail.com>
> wrote:
>
>> I have read the first few pages of this cube sphere and the idea is that
>> you create a cube with multiple points centered at origin.
>> Then when you normalise all the points of that cube and multiply by some
>> distance, say 'r', it will create a sphere with radius 'r'.
>> This I think is a good idea and should not be very difficult to implement.
>>
>>
>> On Tue, 30 Jun 2026 at 07:36, Leonard Martin Struttmann via Discuss <
>> discuss@lists.openscad.org> wrote:
>>
>>> Wow! The octahedron based sphere would be complicated. I think that
>>> I’ll try something simpler:
>>>
>>> module MYsphere( r=1, d = undef)
>>>
>>> {
>>>
>>> function MYfn(f) = floor((f + 2) / 4) * 4;
>>>
>>> F = MYfn($fn);
>>>
>>> R = is_undef(d) ? r : d / 2;
>>>
>>> p = [ for (a=[-90:180/F:90]) polar_to_rectangular([ R, a ] ) ];
>>>
>>> rotate_extrude(angle = 360, convexity = 10, $fn=F )
>>>
>>> polygon( p );
>>>
>>> }
>>>
>>> Len
>>>
>>> For $fn = 24
>>> [image: image.png]
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>
>> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org