<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.stack.imgur.com/FlT0X.png" rel="nofollow noreferrer" title="Conversion process"><img src="https://i.stack.imgur.com/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>

[{'answer_id': 4473, 'author': 'fred_dot_u', 'author_id': 854, 'author_profile': 'https://3dprinting.stackexchange.com/users/854', 'pm_score': 2, 'selected': False, 'text': '<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>\n<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>\n<p>I found a simplistic formula which provides the radius of the sphere given the length of the side of the cube.</p>\n<pre><code>$fn = 90;\nedge = 10;\ncube([edge, edge, edge], center = true);\nsphere_radius = sqrt((3 * pow((edge/2), 2)));\nsphere(sphere_radius);\n</code></pre>\n<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>\n<p><a href="https://i.stack.imgur.com/MI7qz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MI7qz.png" alt="cube inscribed in sphere" /></a></p>\n<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>\n<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>\n<pre><code>        ____________________________\n  D = \\| (L/2)^2 + (L/2)^2 + (L/2)^2\n</code></pre>\n<p>The letter D in this case appears to be slightly misrepresented as diameter when it should be referred to as radius.</p>\n<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>\n<p><a href="https://i.stack.imgur.com/lAW9Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lAW9Z.png" alt="sphere minus cube" /></a></p>\n'}, {'answer_id': 4480, 'author': 'markshancock', 'author_id': 6417, 'author_profile': 'https://3dprinting.stackexchange.com/users/6417', 'pm_score': 1, 'selected': False, 'text': '<p>So it depends a lot on what you want to do.</p>\n\n<ol>\n<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>\n<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>\n</ol>\n\n<p><a href="https://i.stack.imgur.com/HFqUZm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HFqUZm.jpg" alt="enter image description here"></a></p>\n\n<ol start="3">\n<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>\n<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>\n</ol>\n'}, {'answer_id': 4482, 'author': 'mbmcavoy', 'author_id': 5704, 'author_profile': 'https://3dprinting.stackexchange.com/users/5704', 'pm_score': 3, 'selected': True, 'text': '<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>\n\n<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>\n\n<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>\n\n<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>\n\n<p>I won\'t try to explain how to create the actual program as that is not in the scope of 3D printing.</p>\n'}]
['https://3dprinting.stackexchange.com/questions/4471', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/5874/']