2
$\begingroup$

I am a new Mathematica user.

For one of my first projects, I am attempting to graph the locus of all points that are a unit distance from a rectangular prism with given dimensions.

I have no idea how to do this, except potentially graphing the components of the graph individually (eight eighth-spheres, 12 quarter-cylinders, and a rectangular prism). This seems very tedious.

I would appreciate it if anyone helped me to do this.

p2 = {Ball[{0, 0, 0}, 1]}
p1 = {Ball[{0, 0, 10}, 1]}
p3 = {Ball[{4, 0, 10}, 1]}
p4 = {Ball[{4, 8, 10}, 1]}
p5 = {Ball[{0, 8, 0}, 1]}
p6 = {Ball[{0, 8, 10}, 1]}
p7 = {Ball[{4, 0, 0}, 1]}
p8 = {Ball[{4, 8, 0}, 1]}

Show[Graphics3D[p1], Graphics3D[p2], Graphics3D[p3], Graphics3D[p4], 
 Graphics3D[p5], Graphics3D[p6], Graphics3D[p7], Graphics3D[p8], 
 Graphics3D[Cuboid[{0, 0, 0}, {4, 8, 10}]] , 
 Graphics3D[Cuboid[{0, 0, 0}, {-1, 8, 10}]] , 
 Graphics3D[Cuboid[{0, 0, 0}, {0, 8, 10}]] PlotRange -> All]
$\endgroup$
7
  • 2
    $\begingroup$ Welcome to the Mathematica Stack Exchange. The introductory book written by the inventor is a good learning resource. There is a fast intro for math students as well as a fast intro for programmers to choose from. $\endgroup$
    – Syed
    Commented Sep 2, 2023 at 1:18
  • 2
    $\begingroup$ Please post the Mathematica code about rectangular prism and something you have try. $\endgroup$
    – cvgmt
    Commented Sep 2, 2023 at 1:38
  • $\begingroup$ Sorry, what does this mean? $\endgroup$ Commented Sep 2, 2023 at 3:50
  • $\begingroup$ For example ,what is rectangular prism ?Graphics3D[Cuboid[{0, 0, 0}, {3, 4, 5}], Boxed -> False]? We need to post the Mathematica code in this forum. $\endgroup$
    – cvgmt
    Commented Sep 2, 2023 at 3:57
  • $\begingroup$ Sure that is rectangular prism. Sorry, im new here $\endgroup$ Commented Sep 2, 2023 at 4:03

2 Answers 2

5
$\begingroup$
  • One way is RegionDilation according to a unit ball Ball[{0, 0, 0}, 1].
Graphics3D[{FaceForm[Yellow], EdgeForm[], 
  RegionDilation[Cuboid[{0, 0, 0}, {4, 8, 10}], Ball[{0, 0, 0}, 1]]}, 
 Boxed -> False]

enter image description here

  • Or defined a RegionDistanceFunction and use ContourPlot3D to draw the level set equal to 1.
Clear[reg, dist];
reg = Cuboid[{0, 0, 0}, {4, 8, 10}];
dist = RegionDistance@reg;
ContourPlot3D[
 dist@{x, y, z} == 1, {x, -2, 6}, {y, -2, 10}, {z, -2, 12},BoxRatios -> Automatic]

enter image description here

  • We can also use the function OpenCascadeShapeFillet in OpenCascadeLink. But we need to expand the Cuboid[{0,0,0},{x,y,z}] to Cuboid[{-r, -r, -r}, {x + r, y + r, z + r}]] at first.
Needs["OpenCascadeLink`"];
Needs["NDSolve`FEM`"];
r = 1;
{x, y, z} = {4, 8, 10};
shape = OpenCascadeShape[
   Cuboid[{-r, -r, -r}, {x + r, y + r, z + r}]];
fillet = OpenCascadeShapeFillet[shape, r];
bmesh = OpenCascadeShapeSurfaceMeshToBoundaryMesh[fillet, 
   "ShapeSurfaceMeshOptions" -> {"AngularDeflection" -> 0.1}];
groups = bmesh["BoundaryElementMarkerUnion"];
colors = ColorData["BrightBands"] /@ Subdivide[Length@groups];
bmesh["Wireframe"[
  "MeshElementStyle" -> (Directive@{EdgeForm[], FaceForm[#]} & /@ 
     colors)]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you! Is there any way to make the components of the solid appear individuakly? $\endgroup$ Commented Sep 7, 2023 at 19:11
2
$\begingroup$
Clear["Global`*"];
c1 = Cuboid[{0, 0, 0}, {4, 8, 10}];
df = RegionDistance[c1];
reg[r_] := ImplicitRegion[df[{x, y, z}] <= r, {x, y, z}]

Show[
 Region[Style[reg[1], Opacity[0.5, Lighter@Blue]]]
 , Region[Style[c1, Opacity[0.5, Lighter@Red]]]
 ]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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