7
$\begingroup$

I have a simple polygonal region difference:

(* Define quaters of the cross section *)
qlr = Map[# - {-0, 600 + 12} &, {{0, 0}, {300/2, 0}, {300/2, 12}, 
          {12/2 + 120, 12}, {12/2 + 120, 12 + 13}, {12/2 + 13, 12 + 13}, 
          {12/2 + 13, 12 + 120}, {12/2, 12 + 120}, {12/2, 12 + 600}, 
          {0, 12 + 600}, {0, 0}}];
qur = Map[#*{1, -1} &, qlr];
qul = Map[#*{-1, -1} &, qlr];
qll = Map[#*{-1, 1} &, qlr];

(* Define cross section *)
cs = RegionUnion[Region[Polygon[qlr]], Region[Polygon[qur]], Region[Polygon[qul]], Region[Polygon[qll]]]

(* Define holes *)
holes = {{50, -1000}, {73, -1000}, {73, 1000}, {50, 1000}, {50, -1000}};
holes2 = Map[#*{-1, 1} &, {{50, -1000}, {73, -1000}, {73, 1000}, {50, 1000}, {50, -1000}}];
rh = RegionUnion[Region[Polygon[holes]], Region[Polygon[holes2]]]

(* Substract holes *)
RegionDifference[cs, rh]

When I execute the last line without suppressing the output, my PC (MMA 13.2 on Ubuntu 22.04) becomes unusable in approximately 10 seconds. I recommend to save your work before trying this.

Why does this happen? How can I avoid this?

$\endgroup$

1 Answer 1

7
$\begingroup$
  • Use BoundaryDiscretizeRegion before RegionDifference.( Here we also remove Region)
qlr = Map[# - {-0, 600 + 12} &, {{0, 0}, {300/2, 0}, {300/2, 
     12}, {12/2 + 120, 12}, {12/2 + 120, 12 + 13}, {12/2 + 13, 
     12 + 13}, {12/2 + 13, 12 + 120}, {12/2, 12 + 120}, {12/2, 
     12 + 600}, {0, 12 + 600}, {0, 0}}];
qur = Map[#*{1, -1} &, qlr];
qul = Map[#*{-1, -1} &, qlr];
qll = Map[#*{-1, 1} &, qlr];
cs = RegionUnion[Polygon[qlr], Polygon[qur], Polygon[qul], 
   Polygon[qll]];
holes = {{50, -1000}, {73, -1000}, {73, 1000}, {50, 
    1000}, {50, -1000}};
holes2 = 
  Map[#*{-1, 1} &, {{50, -1000}, {73, -1000}, {73, 1000}, {50, 
     1000}, {50, -1000}}];
rh = RegionUnion[Polygon[holes], Polygon[holes2]];
RegionDifference[BoundaryDiscretizeRegion@cs, 
 BoundaryDiscretizeRegion@rh]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Thank you. Do you think it is appropriate to report a bug? I think MMA should not crash just because I try to take a RegionDifference without prior discretization. $\endgroup$ Aug 30, 2023 at 12:22
  • 2
    $\begingroup$ @RainerGlüge I think it is one of the bugs in the region function. $\endgroup$
    – cvgmt
    Aug 30, 2023 at 12:37

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.