# Why does RegionDifference crash my PC?

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?

• 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] • 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. Aug 30 at 12:22
• @RainerGlüge I think it is one of the bugs in the region function. Aug 30 at 12:37