Updated
System Info: HONOR laptop AMD Ryzen 5 4600H 3Hz 6 cores 16GB Memory,
Windows 10 Pro 64 bit with updates.
Mathematica Info: Versions 12.2 and 13.2, both on the same laptop.
Examples:
p1 = RandomPolygon[{"Simple", 50}, DataRange -> {{1, 2}, {1, 2}}];
p2 = RandomPolygon[{"Simple", 50}, DataRange -> {{1, 2}, {1, 2}}];
Timing[RegionIntersection[p1, p2] === EmptyRegion[2]]
WM 12.2: 0.1-0.3 s vs WM 13.2: 3.1-3.6 s
Timing[RegionDifference[p1, p2]]
WM 12.2: 0.3-0.34 s vs WM 13.2: 3.4-3.5 s
Timing[RegionUnion[p1, p2]]
WM 12.2: 0.1-0.2 s vs WM 13.2: 0.7-0.9 s
Other operations (graphs, big numbers) do not show such differences, but I still checking.
More specific question
For one demo, I'd like to create shapes like this one:
Not too complex (without holes and self-intersections),
so the output is just simple polygon with 30-50 vertices:
bf[p_, s_] :=
BSplineFunction[p, SplineClosed -> True, SplineDegree -> s];
initialShape =
With[{pts = RandomReal[{0.2, 0.6}, {9, 2}]*CirclePoints[9]},
Polygon[Table[ bf[pts, 4][t], {t, 0, 1, 0.02}]]
];
shape[center_, size_] :=
TranslationTransform[center][
ScalingTransform[{size, size}][initialShape]];
For further I need to analyze the intersections of these figures.
The problem with RegionDisjoint
has already been described here,
and in version 13.2 it still remained:
RegionDisjoint[shape[{1., 1.}, 1.], shape[{5., 5.}, 2.]]
OK, we can use RegionIntersection
:
isNonIntersect[shape1_, shape2_] :=
RegionIntersection[shape1, shape2] === EmptyRegion[2];
It works, but I found big oddities with the timing of RegionIntersection
:
Result:
True Version 12.2: 0.06-0.08s Version 13.2: 1.2-1.3s
False Version 12.2: 0.0s Version 13.2: 0.01-0.2s
Why does it take longer to get True
, and why Mathematica 13.2 is so slow?!
(all it runs on the same laptop with Win 10)
BoundaryDiscretizeRegion
orDiscretizeRegion
to the polygon; as far as I know it should result equivalent region, at least for polygons with machine-precision coordinate values. Also, mesh regions tend to behave better on intersections etc. than polygons. $\endgroup$SeedRandom
value andshape
specifications. $\endgroup$DiscretizeRegion
butBoundaryMeshRegion
works very well $\endgroup$