2
$\begingroup$

I have two polygons poly1 and poly0, I need the difference area of them. Below is my trial:

poly0 = Import["t0.txt", "Data"]
poly1 = Import["t1.txt", "Data"]

Graphics[{Red, Polygon@poly0 , Green, Polygon@poly1}]

enter image description here

RegionDifference[BoundaryDiscretizeRegion[Polygon@poly1], 
 BoundaryDiscretizeRegion[Polygon@poly0]]

enter image description here

Obviously, the RegionDifference cannot work normally.

enter image description here

data

https://www.dropbox.com/s/6inghzi80uembji/t0.txt?dl=0

https://www.dropbox.com/s/w2j0iui9alzwdsm/t1.txt?dl=0

$\endgroup$
3
  • $\begingroup$ Are you sure you don't have some old definitions? Try clearing all global variables or quitting the kernel. I have no problem with getting the RegionMeasure of RegionMeasure as in your post, as well as in Mauricio's answer. $\endgroup$
    – corey979
    Commented Nov 14, 2016 at 9:24
  • $\begingroup$ @corey979 Yes, In addtion, I guess your Mathematica version is V11.0.1, rather than 10.4 or 11.0.0 $\endgroup$
    – user123
    Commented Nov 14, 2016 at 9:45
  • $\begingroup$ No, I'm on 10.4.1 for Linux x86 (64-bit). $\endgroup$
    – corey979
    Commented Nov 14, 2016 at 9:47

1 Answer 1

2
$\begingroup$

Try using DiscretizeRegion first

r1 = DiscretizeRegion@Polygon@poly0;
r2 = DiscretizeRegion@Polygon@poly1;
rd = RegionDifference[r2, r1]
RegionMeasure@rd

enter image description here

$\endgroup$
8
  • $\begingroup$ I got this i.sstatic.net/SHfE5.png in Mma 10.4 $\endgroup$
    – user123
    Commented Nov 14, 2016 at 7:44
  • $\begingroup$ hmmm .... weird .... I am using Mathematica 11. Perhaps there were some problems with RegionDifference in 10.4. Sorry, no idea in that case $\endgroup$ Commented Nov 14, 2016 at 7:51
  • $\begingroup$ That's all right:) Mma 11 also fails to return the result you give. $\endgroup$
    – user123
    Commented Nov 14, 2016 at 7:55
  • $\begingroup$ What?? In Mma 11 it does not work for you? Did you just copy paste the code I posted? It should work with Mma 11. $\endgroup$ Commented Nov 14, 2016 at 7:59
  • $\begingroup$ Yes, here is the snapshot i.sstatic.net/GFm4r.png $\endgroup$
    – user123
    Commented Nov 14, 2016 at 8:05

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.