5
$\begingroup$

Description

I have been working with derived geometric regions and ran into a problem when deriving RegionIntersection of a Cone with respect to a bounding Cuboid

Example 1

Module[
 {
  R1 = Cuboid[{0, 0, 0}, {5, 5, 5}],
  R2 = Cone[{{0, 0, 0}, {5, 5, 5}}, 3]
  },
 Show[{
   Graphics3D[{Opacity @ 0.05, R2}],
   RegionPlot3D[R1, PlotStyle -> Directive[White, Opacity @ 0.3]],
   RegionPlot3D[RegionIntersection[R2, R1]]
   },
  Boxed -> False]
 ]

Output 1

example no. 1

Example 2

Module[
 {
  R1 = Fold[RegionDifference, 
    Cuboid[{0, 0, 0}, {5, 5, 5}], {Cylinder[{{1, 1, 0}, {1, 1, 5}}, 
      1], Cylinder[{{3, 3, 0}, {3, 3, 5}}, 1]}],
  R2 = Cone[{{0, 0, 0}, {5, 5, 5}}, 3]
  },
 Show[{
   Graphics3D @ {Opacity @ 0.05, Cone[{{0, 0, 0}, {5, 5, 5}}, 3]},
   RegionPlot3D[R1, PlotStyle -> Directive[White, Opacity @ 0.3]],
   RegionPlot3D[RegionIntersection[R1, R2]]
   },
  Boxed -> False]
 ]

Output 2

example 2

EDIT1 (Example of somewhat desired output using alternative solid geometry)

Code

Module[
 {
  module  = Fold[RegionDifference, Cuboid[{0, 0, 0}, {5, 5, 5}], {Cylinder[{{1, 1, 0}, {1, 1, 5}}, 1], Cylinder[{{3, 3, 0}, {3, 3, 5}}, 1]}],
  tetra = Tetrahedron[{{0, 2, 0}, {2, 0, 0}, {0, 0, 2}, {5, 5, 5}}]
  },
 Show[{
   RegionPlot3D[module, PlotStyle -> Directive[White, Opacity @ 0.3]],
   RegionPlot3D @ RegionIntersection[module, tetra]
   }]
 ]

Output

alternative geometry

In the above examples, on both outputs I was expecting a filled Cone region with its base lining-up against the bounding Cuboid. However, the output left me puzzled and I was hoping someone could explain me if I am missing something and how I could achieve the desired output?

$\endgroup$
  • 1
    $\begingroup$ RegionIntersection is just not good at 3D.... It will not work if the regions are MeshRegions, it does work for some special geometric regions but in this case it explicitly gives the wrong answer. You can see a related, but different problem, if you run this on your first example: {Show[Graphics3D /@ {R1, R2}] , RegionPlot3D[{R1, R2}]} $\endgroup$ – Jason B. Jun 21 '16 at 15:06
  • $\begingroup$ @Jasonisnolongerapostdoc is there a known reason for this? How could I formulate a workaround to this problem? I would be interested to use conical regions with more complex geometric configurations :s $\endgroup$ – e.doroskevic Jun 21 '16 at 15:11
  • $\begingroup$ I don't know why it won't work in this case, I've been hoping for a RegionIntersection for 3D MeshRegions for a while now. In terms of a workaround - you want to show the whole cone with an opacity of 0.05 like above, but with the portion of the cone inside the cube in the normal orange (or some other style specified later)? And you'd like to be able to see inside the orange cone section? That last bit is tricky, haven't got it yet $\endgroup$ – Jason B. Jun 21 '16 at 15:22
  • $\begingroup$ I have also tried a few ways around but can't seem to get it to work. Ideally, I would like this Cone to include only the parts which are present in R1 as shown in the example no. 2. R1 may change (imagine it to be some sort of a room with obstacles). I would be interested in a generic solution. Given this region is derived, I will be using it in RandomPoint to generate an arbitrary no. of points. $\endgroup$ – e.doroskevic Jun 21 '16 at 15:31
  • 1
    $\begingroup$ I am running 10.3.1 on Windows 7 x64 $\endgroup$ – e.doroskevic Jun 21 '16 at 16:17
3
$\begingroup$

To make the tetrahedra solution give a better result, you need to increase the PlotPoints, like this:

Module[
  {
    module = Fold[
      RegionDifference,
      Cuboid[{0, 0, 0}, {5, 5, 5}],
      {
        Cylinder[{{1, 1, 0}, {1, 1, 5}}, 1],
        Cylinder[{{3, 3, 0}, {3, 3, 5}}, 1]
      }
    ],
    tetra = Tetrahedron[{{0, 2, 0}, {2, 0, 0}, {0, 0, 2}, {5, 5, 5}}]
  },
  Show[
    {
      RegionPlot3D[
        module, 
        PlotStyle -> Directive[White, Opacity@0.3]
      ], 
      RegionPlot3D[
        RegionIntersection[module, tetra], 
        PlotPoints -> 100, 
        Mesh -> All
      ]
    },
    ImageSize -> Medium
  ]
]

Tetrahedron with 100 PlotPoints

And to get a good RegionPlot of the original code, you should discretize the region in the RegionPlot3D:

Module[
 {
   R1 = Cuboid[{0, 0, 0}, {5, 5, 5}],
   R2 = Cone[{{0, 0, 0}, {5, 5, 5}}, 3]
  },
  Show[
    {
      Graphics3D[{Opacity@0.05, R2}],
      RegionPlot3D[R1, PlotStyle -> Directive[White, Opacity@0.3]],
      RegionPlot3D[
        DiscretizeRegion[RegionIntersection[R2, R1], PrecisionGoal -> 10]
      ]
    },
    Boxed -> False
  ]
]

Discretized RegionIntersection

Note: the PrecisionGoal smooths the surface of the RegionIntersection object

I hope this helps. You may find many calculations struggle on the direct symbolic solution of 3D region intersections, in those cases try discretizing the region first (you can increase different precision options to DiscretizeRegion for better results).

Nia Knibbs Vaughan
Wolfram Research Technical Consultant

| improve this answer | |
$\endgroup$
  • $\begingroup$ What version of Mathematica did you use to produce the cone intersection? $\endgroup$ – e.doroskevic Nov 15 '16 at 11:04
  • $\begingroup$ My Mathematica version is 11.0.1.0 (and am using Windows 10). $\endgroup$ – lowriniak Nov 15 '16 at 11:09
  • $\begingroup$ The reason why I am asking is because the cone doesn't seem to discretize on version 10.3 :s It works with tetrahedron though $\endgroup$ – e.doroskevic Nov 15 '16 at 11:20
  • $\begingroup$ Interesting. DiscretizeRegion has not been updated between the versions (see here for more info - bottom of the page has update information) so there should be no difference. It is possible that an option needs to be modified, could you post/describe the issue you are having with the cone? $\endgroup$ – lowriniak Nov 15 '16 at 11:24
  • $\begingroup$ I did refer to the documentation, I think I might be missing something obvious... but here is the screenshot $\endgroup$ – e.doroskevic Nov 15 '16 at 11:33

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.