1
$\begingroup$

I am testing my idea to find the difference between two regions, while one region has discrete sub-regions. I find that RegionUnion and RegionDifference have problems dealing with such problems. I post my script here for a quick check

 `d1 = Disk[{0.5, 0.5}, 0.4];
  d2 = Disk[{1.5, 1.5}, 0.4];
  d3 = Disk[{1.5, 0.5}, 0.4];
  d4 = Disk[{0.5, 1.5}, 0.4];
  u1 = Region[RegionUnion[d1, d2, d3, d4], Axes -> True, 
   AxesOrigin -> {0, 0}]
  RegionDimension[u1]
   Area[u1]
  u2 = Region[Rectangle[{0, 0}, {2, 2}], Axes -> True, 
   AxesOrigin -> {0, 0}]
  RegionDimension[u2]
  D1 = Region[RegionDifference[u2, u1], Axes -> True, 
   AxesOrigin -> {0, 0}]

I hope to get the region without those four disks in the rectangle. but the code just give the region of the left corner part.

Thanks for any comments.

$\endgroup$
  • $\begingroup$ Region isn't a valid command. Just do, eg: u1 = RegionUnion[d1, d2, d3, d4], and the RegionPlot[u1]. Also, probably don't want to be using capital D as a variable name. $\endgroup$ – aardvark2012 Oct 7 '17 at 7:32
  • $\begingroup$ Thanks. That means Region command is not a command to define a region, and we don't need to define something as region before apply region related commands. Is it right? $\endgroup$ – Dai Weijing Oct 8 '17 at 23:36
  • $\begingroup$ Ah, apparently Region is a command. Introduced in v.11, presumably. Sorry, my bad. But yeah, not a command to define a region. $\endgroup$ – aardvark2012 Oct 8 '17 at 23:40
2
$\begingroup$

Only use Region when you want to view the region. The following does what you want:

u1 = RegionUnion[d1, d2, d3, d4];
u2 = Rectangle[{0,0}, {2,2}];
Region @ RegionDifference[u2, u1]

enter image description here

$\endgroup$

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.