<p>The calculations for your objective could be considered simple geometry, although the results in terms of formulae are a bit more complex than simple, but not by much.</p>
<p>According to <a href="https://www.quora.com/What-is-the-volume-of-the-largest-cube-that-can-be-fitted-inside-a-sphere-of-radius-R" rel="nofollow noreferrer">Quora</a>, the foundation for this goal is that the cube's eight vertices will be coincidental to the sphere's surface. If one desires to print a 3D object with this form, such an object may fail the requirement of being manifold, but may not, depending on the floating point operations of the software being used.</p>
<p>I found a simplistic formula which provides the radius of the sphere given the length of the side of the cube.</p>
<pre><code>$fn = 90;
edge = 10;
cube([edge, edge, edge], center = true);
sphere_radius = sqrt((3 * pow((edge/2), 2)));
sphere(sphere_radius);
</code></pre>
<p>The above code is done in <a href="https://openscad.org/" rel="nofollow noreferrer">OpenSCAD</a>, resulting in this image with the sphere made transparent for clarity:</p>
<p><a href="https://i.sstatic.net/MI7qz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MI7qz.png" alt="cube inscribed in sphere" /></a></p>
<p>Translated into general English, it appears that one can take the edge length, divided by 2, then take the square of that result and triple it. Take the square root of that value and it becomes the radius of the sphere.</p>
<p>The above answer is courtesy of <a href="https://web.archive.org/web/20171123112402/http://mathforum.org/library/drmath/view/62515.html" rel="nofollow noreferrer">Math Forum</a> and is represented verbatim as such:</p>
<pre><code>        ____________________________
  D = \| (L/2)^2 + (L/2)^2 + (L/2)^2
</code></pre>
<p>The letter D in this case appears to be slightly misrepresented as diameter when it should be referred to as radius.</p>
<p>As part of this fun exercise, I also subtracted the cube from the sphere, slicing it in half for visibility, resulting in this image:</p>
<p><a href="https://i.sstatic.net/lAW9Z.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lAW9Z.png" alt="sphere minus cube" /></a></p>

CC BY-SA 4.0
2017-08-08T23:52:33.597Z
2022-09-13T20:01:35.673Z
2022-09-13T20:01:35.673Z
fred_dot_u
<p>So it depends a lot on what you want to do.</p>

<ol>
<li><p>If you want to mathematically calculate what cube fits in what size sphere, that is straight forward.  The <a href="http://mathcentral.uregina.ca/qq/database/qq.09.04/brett1.html" rel="nofollow noreferrer">diagonal for the cube</a> has to fit into the diameter of the shere.  For a cube with edge 'l' and a shpere with diamamer 'd' then  <img src="https://chart.googleapis.com/chart?cht=tx&amp;chl=4l%5Csqrt%7B3%7D" alt=""> &lt;= d.</p></li>
<li><p>If you want to model a cube and a sphere in CAD (or one inside the other) you just do it.  They are both primitives.  Takes less than a minute.</p></li>
</ol>

<p><a href="https://i.sstatic.net/HFqUZm.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/HFqUZm.jpg" alt="enter image description here"></a></p>

<ol start="3">
<li><p>You can use a mesh in a design too.  I would assume if you are wanting to use a mesh, the mesh must contain something other than just a smooth bowl or what the point of the mesh?  Fusion 360 allows you to import a mesh and play with it just like that and combine it with model objects (just like the box).  </p></li>
<li><p>You can actually convert a mesh into a solid model if you want to too.  Fusion 360 CAD has ways to help you convert that mesh to a sculpt.  First create a sculpt object that represents the shape of the mesh object (like a sphere or a quadraball).  Next import the mesh then collapse the model over the mesh (using it like a model to form a mold).  You can then delett the mesh and use the molded sculpt.</p></li>
</ol>

CC BY-SA 3.0
2017-08-10T06:07:49.143Z
2017-08-11T14:46:49.140Z
2017-08-11T14:46:49.140Z
markshancock
<p>The answers by @markshancock and @fred-dot-u describe the process of creating a CAD primitive sphere and subtracting a cube; this is a trivial task in most any 3D CAD program. You could manually measure the mesh to determine its dimensions, and frankly, I would recommend this approach. (If you have a large task like converting 100,000 half-sphere meshes, I'd re-think the approach and go to the source that generated the meshes in the first place!)</p>

<p>However, these don't address converting the mesh to a primitive, which is normally not possible for arbitrary meshes (therefore a CAD program will not have such a function), and much more difficult than simply measuring and re-creating.</p>

<p>You assert that your mesh file "has the perfect shape of half a sphere". A mesh is basically on a collection of vertices, joined by edges and faces. The vertices are defined by numeric coordinates, and in a computer will always have some rounding errors, and the linear edges and planar faces are most definitely not round. Therefore, it may be incredibly close, but it will most definitely not be perfect.</p>

<p>In this <em>very</em> particular case, the diameter of the sphere is the same as the diameter of the circular face of your half-sphere. You could plausibly write a simple program that would locate the maximum distance between any two vertices in your mesh and use that for the diameter. The midpoint of the line between those two points would be the center of the sphere. This should produce a good result but may not be "exact" depending on the details of the mesh.</p>

<p>I won't try to explain how to create the actual program as that is not in the scope of 3D printing.</p>

CC BY-SA 3.0
2017-08-11T15:49:00.340Z
2017-08-11T15:49:00.340Z
mbmcavoy
<p>I have a mesh of a bowl that has the perfect shape of half a sphere. I want to easily convert it to the containing sphere solid and a box solid that will be subtracted from it.</p>

<p><a href="https://i.sstatic.net/FlT0X.png" rel="nofollow noreferrer" title="Conversion process"><img src="https://i.sstatic.net/FlT0X.png" alt="Conversion process" title="Conversion process"></a></p>

<p>Googling mesh to solid shows that in various tools such as 3ds Max, Fusion, etc., manual approximation of where the sphere might go is created manually by visually comparing to the mesh or the cross section when creating the solid but I am looking for the minimum enclosing sphere and box to be generated/calculated by the software.</p>

<p>Source file format is of course not an issue, it can be any known mesh file.</p>

<3d-models><cad>
Converting a mesh to constructive solid geometry
Rott
# Converting a mesh to constructive solid geometry

(Asked by: username_0 on 2017-08-08)

I have a mesh of a bowl that has the perfect shape of half a sphere. I want to easily convert it to the containing sphere solid and a box solid that will be subtracted from it.

[![Conversion process](https://i.sstatic.net/FlT0X.png "Conversion process")](https://i.sstatic.net/FlT0X.png "Conversion process")

Googling mesh to solid shows that in various tools such as 3ds Max, Fusion, etc., manual approximation of where the sphere might go is created manually by visually comparing to the mesh or the cross section when creating the solid but I am looking for the minimum enclosing sphere and box to be generated/calculated by the software.

Source file format is of course not an issue, it can be any known mesh file.

**Tags:** 3d-models, cad

---

## 3 answers

### Answer by username_3 on 2017-08-11. Score: 3 | Accepted answer

The answers by @markshancock and @fred-dot-u describe the process of creating a CAD primitive sphere and subtracting a cube; this is a trivial task in most any 3D CAD program. You could manually measure the mesh to determine its dimensions, and frankly, I would recommend this approach. (If you have a large task like converting 100,000 half-sphere meshes, I'd re-think the approach and go to the source that generated the meshes in the first place!)

However, these don't address converting the mesh to a primitive, which is normally not possible for arbitrary meshes (therefore a CAD program will not have such a function), and much more difficult than simply measuring and re-creating.

You assert that your mesh file "has the perfect shape of half a sphere". A mesh is basically on a collection of vertices, joined by edges and faces. The vertices are defined by numeric coordinates, and in a computer will always have some rounding errors, and the linear edges and planar faces are most definitely not round. Therefore, it may be incredibly close, but it will most definitely not be perfect.

In this *very* particular case, the diameter of the sphere is the same as the diameter of the circular face of your half-sphere. You could plausibly write a simple program that would locate the maximum distance between any two vertices in your mesh and use that for the diameter. The midpoint of the line between those two points would be the center of the sphere. This should produce a good result but may not be "exact" depending on the details of the mesh.

I won't try to explain how to create the actual program as that is not in the scope of 3D printing.


---

### Answer by username_1 on 2017-08-08. Score: 2

The calculations for your objective could be considered simple geometry, although the results in terms of formulae are a bit more complex than simple, but not by much.
According to Quora, the foundation for this goal is that the cube's eight vertices will be coincidental to the sphere's surface. If one desires to print a 3D object with this form, such an object may fail the requirement of being manifold, but may not, depending on the floating point operations of the software being used.
I found a simplistic formula which provides the radius of the sphere given the length of the side of the cube.
$fn = 90;
edge = 10;
cube([edge, edge, edge], center = true);
sphere_radius = sqrt((3 * pow((edge/2), 2)));
sphere(sphere_radius);

The above code is done in OpenSCAD, resulting in this image with the sphere made transparent for clarity:

Translated into general English, it appears that one can take the edge length, divided by 2, then take the square of that result and triple it. Take the square root of that value and it becomes the radius of the sphere.
The above answer is courtesy of Math Forum and is represented verbatim as such:
        ____________________________
  D = \| (L/2)^2 + (L/2)^2 + (L/2)^2

The letter D in this case appears to be slightly misrepresented as diameter when it should be referred to as radius.
As part of this fun exercise, I also subtracted the cube from the sphere, slicing it in half for visibility, resulting in this image:


---

### Answer by username_2 on 2017-08-10. Score: 1

So it depends a lot on what you want to do.

1. If you want to mathematically calculate what cube fits in what size sphere, that is straight forward. The [diagonal for the cube](http://mathcentral.uregina.ca/qq/database/qq.09.04/brett1.html) has to fit into the diameter of the shere. For a cube with edge 'l' and a shpere with diamamer 'd' then ![](https://chart.googleapis.com/chart?cht=tx&chl=4l%5Csqrt%7B3%7D) <= d.
2. If you want to model a cube and a sphere in CAD (or one inside the other) you just do it. They are both primitives. Takes less than a minute.

[![enter image description here](https://i.sstatic.net/HFqUZm.jpg)](https://i.sstatic.net/HFqUZm.jpg)

3. You can use a mesh in a design too. I would assume if you are wanting to use a mesh, the mesh must contain something other than just a smooth bowl or what the point of the mesh? Fusion 360 allows you to import a mesh and play with it just like that and combine it with model objects (just like the box).
4. You can actually convert a mesh into a solid model if you want to too. Fusion 360 CAD has ways to help you convert that mesh to a sculpt. First create a sculpt object that represents the shape of the mesh object (like a sphere or a quadraball). Next import the mesh then collapse the model over the mesh (using it like a model to form a mold). You can then delett the mesh and use the molded sculpt.


---

