Mathematica Asked by Rainer on February 17, 2021
There is a nice example of how to generate an isometric visualisation of surfaces which are at a constant distance from a given region.
All these examples are just working on one single region. If one tries to apply this functionality to RegionUnions then the evaluation does not yield any results. E.g. a simple union of two cuboids with subsequent plotting of the surface which is 0.25 away from their surfaces yields no result:
ContourPlot3D[Evaluate@RegionDistance[RegionUnion[
Cuboid[{-5, -5, 0}, {5, 5, 1}],
Cuboid[{-10, -10, -10}, {10, 10, 0}]], {x, y, z}],
{x, -7, 7}, {y, -7, 7}, {z, 0, 2},
Mesh -> None, Contours -> {0.25},
ContourStyle -> ColorData[94, "ColorList"], Lighting -> "Neutral",
BoxRatios -> Automatic]
whereas the simpler command with just one cuboid generates the expected result:
ContourPlot3D[Evaluate@RegionDistance[
Cuboid[{-5, -5, 0}, {5, 5, 1}], {x, y, z}],
{x, -7, 7}, {y, -7, 7}, {z, 0, 2},
Mesh -> None, Contours -> {0.25},
ContourStyle -> ColorData[94, "ColorList"], Lighting -> "Neutral",
BoxRatios -> Automatic]
Potentially the functionality is just limited to single entities and not unions? Any ideas how to achieve this for Region Unions or Intersections?
If you try evaluating your RegionDistance
object for a point you will see that it doesn't work:
RegionDistance[
RegionUnion[Cuboid[{-5,-5,0},{5,5,1}],Cuboid[{-10,-10,-10},{10,10,0}]],
{1,-1,2}
] //InputForm
RegionDistance[Polyhedron[{{-5., -5., 0.}, {5., -5., 0.}, {5., -5., 1.}, {-5., -5., 1.}, {5., 5., 0.}, {-5., 5., 0.}, {-5., 5., 1.}, {5., 5., 1.}, {5., -5., -10.}, {-5., -5., -10.}, {-5., 5., -10.}, {5., 5., -10.}, {10., -5., -10.}, {10., 5., -10.}, {10., 5., 0.}, {10., -5., 0.}, {-10., 5., -10.}, {-10., -5., -10.}, {-10., -5., 0.}, {-10., 5., 0.}, {10., 10., -10.}, {-10., 10., -10.}, {-10., 10., 0.}, {10., 10., 0.}, {-10., -10., -10.}, {10., -10., -10.}, {10., -10., 0.}, {-10., -10., 0.}}, {{1, 2, 3, 4}, {5, 6, 7, 8}, {6, 1, 4, 7}, {2, 5, 8, 3}, {4, 3, 8, 7}, {9, 10, 11, 12}, {13, 14, 15, 16}, {14, 13, 9, 12}, {16, 15, 5, 2}, {17, 18, 19, 20}, {10, 18, 17, 11}, {6, 20, 19, 1}, {21, 22, 23, 24}, {22, 17, 20, 23}, {14, 21, 24, 15}, {25, 26, 27, 28}, {18, 25, 28, 19}, {26, 13, 16, 27}, {22, 21, 14, 12, 11, 17}, {15, 24, 23, 20, 6, 5}, {13, 26, 25, 18, 10, 9}, {28, 27, 16, 2, 1, 19}}], {1, -1, 2}]
This is why you don't get a plot. One possible workaround is to discretize your cuboids. Another optimization is to create the RegionDistanceFunction
and then to use it. So:
rdf = RegionDistance @ RegionUnion[
DiscretizeRegion @ Cuboid[{-5,-5,0},{5,5,1}],
DiscretizeRegion @ Cuboid[{-10,-10,-10},{10,10,0}]
];
ContourPlot3D[
rdf[{x,y,z}],
{x,-7,7}, {y,-7,7}, {z,0,2},
Mesh->None,
Contours->{0.25},
ContourStyle->ColorData[94,"ColorList"],
Lighting->"Neutral",
BoxRatios->Automatic
]
Correct answer by Carl Woll on February 17, 2021
Min
work or not?
reg1 = Cuboid[{-5, -5, -12}, {5, 5, 12}];
reg2 = Cuboid[{-10, -10, -10}, {10, 10, 10}];
ContourPlot3D[
Min[RegionDistance[reg1, {x, y, z}],
RegionDistance[reg2, {x, y, z}]] // Evaluate, {x, -15,
15}, {y, -15, 15}, {z, -15, 15}, Mesh -> None, Contours -> {0.25},
ContourStyle -> ColorData[94, "ColorList"], Lighting -> "Neutral",
BoxRatios -> Automatic, PlotRange -> All]
Answered by cvgmt on February 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP