2
$\begingroup$

Consider the following 3D shape as an example:

ClearAll[cylinder];
cylinder[r_,z_]:=Cylinder[{{r,r,0},{r,r,z}},r];

It is a cylinder whose entire SurfaceArea, I can calculate as follows:

Expand@Simplify[SurfaceArea[cylinder[r,z]],Assumptions->z>0]

2 π r^2 + 2 π r z

But I want something like as follows:

<|1 -> π r^2, 2 -> 2 π r z, 3 -> π r^2|>

So if I want the total I can do the following:

Total[%]

I think maybe converting this shape to a Region and then applying some built-in function to get the faces of a 3D Region as separate 2D Regions would be helpful. Then maybe I can map Area on the 2D Regions to find what I need?

$\endgroup$
2
  • $\begingroup$ So in your treatment, a cone will have two faces, and a sphere only one? $\endgroup$
    – J. M.'s torpor
    Feb 3 at 0:49
  • $\begingroup$ @J.M. yes but remember it should be possible to work with composite shapes. That is the entire goal here. $\endgroup$
    – user13892
    Feb 3 at 1:42
4
$\begingroup$

You could use the OpenCascadeLink for this:

ClearAll[cylinder];
cylinder[r_, z_] := Cylinder[{{r, r, 0}, {r, r, z}}, r];
Needs["OpenCascadeLink`"]
s = OpenCascadeShape[cylinder[1, 2]]
fs = OpenCascadeShapeFaces[s];
bms = OpenCascadeShapeSurfaceMeshToBoundaryMesh /@ fs;
#["Wireframe"] & /@ bms

enter image description here

Area[MeshRegion[#]] & /@ bms
{12.546193962183768`, 3.121445152258052`, 3.121445152258052`}

Update: To refine the mesh, have a look in the documentation on the different methods to specify that. One option is to set the "LinearDeflection".

OpenCascadeShapeSurfaceMeshToBoundaryMesh[#, 
  "ShapeSurfaceMeshOptions" -> {"LinearDeflection" -> 0.001}] &
$\endgroup$
4
  • $\begingroup$ This is very interesting. What is OpenCascade? Is it a separate program? Is it included with Mathematica installation? Do I need to install anything extra to make your code work? I don't have access to Mathematica right now and will test it when I am home. $\endgroup$
    – user13892
    Feb 3 at 16:27
  • $\begingroup$ @user13892 Everything is onboard. $\endgroup$
    – user21
    Feb 3 at 20:36
  • $\begingroup$ Is there a way/option to get a denser mesh for the faces? The answers for their Area are not very accurate. $\endgroup$
    – user13892
    Feb 4 at 6:53
  • $\begingroup$ @user13892, see update and documentation. $\endgroup$
    – user21
    Feb 4 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.