Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Semi-spherical container
thomas_kozak
Member Posts: 38 ✭✭
The goal is to design a container (partial sphere) of given volume which is attached to a plane via a port of a given radius. Ideally these would be parametric. I believe this can be done via variables but constructing the expression is giving me problems.
The sketch would be a circle split by a chord of constrained length (2*radius of the port). The radius of the large circle should be definable by the length of the chord and the known area of the resulting circular cap.
The sketch would be a circle split by a chord of constrained length (2*radius of the port). The radius of the large circle should be definable by the length of the chord and the known area of the resulting circular cap.
0
Best Answer
-
NeilCooke Moderator, Onshape Employees Posts: 5,688Create a Feature Studio and paste this code below the header and press "Commit", then run the feature in your Part Studio.
annotation { "Feature Type Name" : "Volume Sphere" } export const VolSphere = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Cap diameter" } isLength(definition.diameter, LENGTH_BOUNDS); annotation { "Name" : "Volume (^3)" } // enter volume as 6000 mm^3 isAnything(definition.volume); } { const capRadius = definition.diameter / 2; var reqVolume = definition.volume; var factor = 1.5; // initial guess var upperBound = 1.99; var lowerBound = 1.01; var arcRadius = capRadius * factor; var volume; for (var i = 0; i < 20; i += 1) { var height = arcRadius - sqrt(arcRadius ^ 2 - capRadius ^ 2); var volumeOfCap = (PI * height) / 6 * (3 * capRadius ^ 2 + height ^ 2); var volumeOfSphere = (4 / 3) * PI * arcRadius ^ 3; volume = volumeOfSphere - volumeOfCap; if (tolerantEquals(volume, reqVolume)) break; if (volume < reqVolume) { lowerBound = factor; factor = (upperBound - factor) / 2 + factor; } if (volume > reqVolume) { upperBound = factor; factor = factor - (factor - lowerBound) / 2; } arcRadius = capRadius * factor; } if (!tolerantEquals(volume, reqVolume)) { throw regenError("Solution could not be found", ["volume"]); } var arcCenter = vector(0 * meter, -sqrt(arcRadius ^ 2 - capRadius ^ 2)); var arcStart = arcCenter - vector(0 * meter, arcRadius); var arcMid = vector(arcRadius, arcCenter[1]); const sketch = newSketchOnPlane(context, id + "sketch", { "sketchPlane" : evPlane(context, { "face" : qCreatedBy(makeId("Front"), EntityType.FACE) }) }); skLineSegment(sketch, "line1", { "start" : vector(0, 0) * meter, "end" : vector(1, 0) * capRadius }); skArc(sketch, "arc1", { "start" : arcStart, "mid" : arcMid, "end" : vector(capRadius, 0 * meter) }); skLineSegment(sketch, "line2", { "start" : arcStart, "end" : vector(0, 0) * meter }); skSolve(sketch); opRevolve(context, id + "revolve1", { "entities" : qSketchRegion(id + "sketch"), "axis" : line(vector(0, 0, 0) * meter, vector(0, 0, 1)), "angleForward" : 360 * degree }); opDeleteBodies(context, id + "deleteBodies1", { "entities" : qCreatedBy(id + "sketch") }); });
Senior Director, Technical Services, EMEAI5
Answers