1
$\begingroup$

Description

I am looking to visualize gas cloud growth within custom modules.

For demonstration purpose, it is assumed gas cloud takes a spherical shape whilst module is defined using a Polygon.

Among many other things, I struggle to extend RegionIntersection to include the entire Polygon as to visualize how gas cloud fills up the available volume.

Please see example below.


Example

Code

DynamicModule[
 {radius = 1,
  region =  {{{0, 0, 0}, {5, 0, 0}, {5, 5, 0}, {4, 5, 0}, {4, 8, 0}, {0, 8, 0}}, {{5, 0, 0}, {5, 0, 5}, {5, 5, 5}, {5, 5, 0}}, {{0, 0, 0}, {0, 0, 5}, {5, 0, 5}, {5, 0, 0}}, {{5, 5, 0}, {5, 5, 5}, {4, 5, 5}, {4, 5, 0}}, {{4, 5, 0}, {4, 5, 5}, {4, 8, 5}, {4, 8, 0}}, {{4, 8, 0}, {4, 8, 5}, {0, 8, 5}, {0, 8, 0}}, {{0, 0, 0}, {0, 0, 5}, {0, 8, 5}, {0, 8, 0}}, {{0, 0, 5}, {5, 0, 5}, {5, 5, 5}, {4, 5, 5}, {4, 8, 5}, {0, 8, 5}}}
 },

 Labeled[
 Panel @ Column[{
     (*Controls*)
     Manipulator[Dynamic @ radius, {1, 10, 1}],

     (*Visual*)
     Dynamic @ Show[{
        Graphics3D @ {Opacity @ 0.3, Polygon @ region},

        (*In RegionIntersection, I use Cuboid to demonstrate what I am after. I would like to replace it with whatever magic necessary to include the entire Polygon*)
        RegionPlot3D @ RegionIntersection[Ball[{2, 2, 2}, radius], Cuboid[{0, 0, 0}, {5, 5, 5}]]
        },
       Boxed -> False,
       ImageSize -> Medium]
     },
    Alignment -> Center],
  Style["Example", 24], Top]
 ]

Output

Example Output


Objective

Essently, I am looking to replace that Cuboid[{0,0,0},{5,5,5}] with something that would allow me to include the entire Polygon. Also, it would be great if solution would be flexible to take any 3D Polygon as a module.


Issues

I.1 [resolved] - A level of confusion has been experienced when messing around with discretization. When deriving regions using spheres, the result differed from what has been initially expected. See code and output below:

Code

GraphicsRow @ {DiscretizeRegion @ 
   RegionDifference[Sphere[{0, 0, 0}, 1], Sphere[{1, 0, 0}, 1]], 
  DiscretizeRegion @ 
   RegionUnion[Sphere[{0, 0, 0}, 1], Sphere[{1, 0, 0}, 1]]}

Output

RegionDifference with Sphere

Whilst I was expecting output such as below.

Code

GraphicsRow @ {DiscretizeRegion @ 
   RegionDifference[Ball[{0, 0, 0}, 1], Ball[{1, 0, 0}, 1]], 
  DiscretizeRegion @ 
   RegionUnion[Ball[{0, 0, 0}, 1], Ball[{1, 0, 0}, 1]]}

Output

RegionDifference with Ball

Although this issue has been resolved, I am not entirely sure why outputs with Ball and Sphere differ. I would be greatful if someone could expand on this matter or provide some reference to read about it.

$\endgroup$
  • $\begingroup$ Remember that Ball[] is a three dimensional solid, and Sphere[] is only the surface (by analogy with Disk[] and Circle[]). $\endgroup$ – J. M. is away Jun 9 '16 at 13:39
  • $\begingroup$ @J.M thanks, the reason why I thought Sphere[] is treated as a solid is because it's noted here: reference.wolfram.com/language/guide/SolidGeometry.html. That's probably the reason why I cannot get my RegionIntersection[..] to work $\endgroup$ – e.doroskevic Jun 9 '16 at 13:44
1
$\begingroup$

Description

This solution does not fully cover the requirements of the original post, but it does achieve the desired output. In order to visualize how arbitrary gas cloud fills up the available volume, I have combined two Cuboid regions using RegionUnion. This new region has then been tested for intersection with a Ball of varying radii using RegionIntersection to achieve the desired output. The issue with this solution is that it is not generic in a way it requires the Polygon to be subsidized with RegionUnion of n Cuboid shapes. At present, I am not sure how to automate this. Please see implementation below.


Solution

This is a module as seen in OP

Code

region = {{{0, 0, 0}, {5, 0, 0}, {5, 5, 0}, {4, 5, 0}, {4, 8, 0}, {0, 8, 0}}, {{5, 0, 0}, {5, 0, 5}, {5, 5, 5}, {5, 5, 0}}, {{0, 0, 0}, {0, 0, 5}, {5, 0, 5}, {5, 0, 0}}, {{5, 5, 0}, {5, 5, 5}, {4, 5, 5}, {4, 5, 0}}, {{4, 5, 0}, {4, 5, 5}, {4, 8, 5}, {4, 8, 0}}, {{4, 8, 0}, {4, 8, 5}, {0, 8, 5}, {0, 8, 0}}, {{0, 0, 0}, {0, 0, 5}, {0, 8, 5}, {0, 8, 0}}, {{0, 0, 5}, {5, 0, 5}, {5, 5, 5}, {4, 5, 5}, {4, 8, 5}, {0, 8, 5}}};

Labeled[
  Graphics3D[

  (*Graphics3D Specification*)
  {EdgeForm @ None, Opacity @ 0.5, Polygon @ region},

  (*Graphics3D Options*)
  Boxed -> False
  ],

  (*Label Specification*)
  Style["Module", 24],

  (*Label Options*)
  Top]

Output

module example

Then I combined two Cuboid entities using RegionUnion to achieve the desired region

Code

Show[RegionPlot3D @ RegionUnion[Cuboid[{0, 0, 0}, {5, 5, 5}], Cuboid[{0, 5, 0}, {4, 8, 5}]], Boxed -> False]

Output

region example

Given the desired region has been derived, I subsidize it into the code presented in OP achieving the desired output

Code

DynamicModule[{
  radius = 1,
  region = {{{0, 0, 0}, {5, 0, 0}, {5, 5, 0}, {4, 5, 0}, {4, 8, 
      0}, {0, 8, 0}}, {{5, 0, 0}, {5, 0, 5}, {5, 5, 5}, {5, 5, 
      0}}, {{0, 0, 0}, {0, 0, 5}, {5, 0, 5}, {5, 0, 0}}, {{5, 5, 
      0}, {5, 5, 5}, {4, 5, 5}, {4, 5, 0}}, {{4, 5, 0}, {4, 5, 5}, {4,
       8, 5}, {4, 8, 0}}, {{4, 8, 0}, {4, 8, 5}, {0, 8, 5}, {0, 8, 
      0}}, {{0, 0, 0}, {0, 0, 5}, {0, 8, 5}, {0, 8, 0}}, {{0, 0, 
      5}, {5, 0, 5}, {5, 5, 5}, {4, 5, 5}, {4, 8, 5}, {0, 8, 5}}}
  },
 Labeled[
  Panel@Column[{
     (*Controls*)
     Manipulator[Dynamic@radius, {1, 7, 1}],
     (*Visual*)
     Dynamic@Show[{
        (*Module*)
        Graphics3D@{Opacity@0.3, Polygon@region},

        (*Gas Cloud*)
        RegionPlot3D @ 
         RegionIntersection[Ball[{2, 2, 2}, radius], 
          RegionUnion[Cuboid[{0, 0, 0}, {5, 5, 5}], 
           Cuboid[{0, 5, 0}, {4, 8, 5}]]]
        },
       (* Show Options*)
       Boxed -> False, ImageSize -> Medium]},
    (* Column Options *)
    Alignment -> Center],
  (*Label Specification*)
  Style["Example", 24], Top]]

Output

final output

$\endgroup$
  • $\begingroup$ In principle you could use BoundaryDiscretizeGraphics[Polygon@region] to convert the polygons to a region, but Mathematica seems unable to discretize the resulting RegionIntersection. $\endgroup$ – Simon Woods Jul 10 '16 at 12:12

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.