4
$\begingroup$

I want to be able to find the area of the intersection between a hexagon and a slice. I have tried RegionMeasure or Area but I seem to get incorrect answers. RegionMeasure gives length when the intersection is a line, so I switched to Area but sometimes it still gives weird answers, when the intersection happens to be a line.

One reason why I think this might occur is that I build the hexagon using Polygon, but the "slice" is with Disk. Is that the problem? How to I make a region as a slice, so that Area[RegionIntersection[hexagon, slice]] between the two regions will always give $0$ for a line intersection and no intersection, i.e. return a nonzero result only for 2D intersection.

See picture. I want to know the area of intersection of the black hexagon will each of the 6 (colored for visualization) slices below. The answer should be non-zero for the 2 upper left slices, and 0 for every other slice, even though some have "line intersections".

the objects

Thanks.

EDIT: The problem is that edges get non-zero measure. Why is the below code giving .7, and not 0?

DiskR = 1.5;
Show[
  Graphics[{Orange, Opacity[0.35], 
  Disk[{0, 0}, DiskR, {Pi/6, 3 Pi/6}]}], 
  Graphics[Polygon[{{0, 0}, {0, .7}, {-1, 1}}]]]

and

Area[
 RegionIntersection[
  Polygon[{{0, 0}, {0, .7}, {-1, 1}}], 
  Disk[{0, 0}, DiskR, {Pi/6, 3 Pi/6}]
 ]
]

enter image description here

$\endgroup$
7
  • $\begingroup$ This certainly works: Polygon[CirclePoints[{-(Sqrt[3]/2), 1/2}, {1, π/6}, 6]] ~RegionIntersection~ Disk[{0, 0}, 3, {π/2, π/2 + π/3}] // Area $\endgroup$ Commented Jun 14, 2016 at 15:52
  • $\begingroup$ But why does a line give non-zero Area? See my edited question. $\endgroup$
    – Ben S
    Commented Jun 14, 2016 at 17:05
  • $\begingroup$ Please post the code as text. Nobody wants to copy it out manually from the image. $\endgroup$ Commented Jun 14, 2016 at 18:08
  • $\begingroup$ Sorry, new here. But I see your point. I edited and pasted the code. $\endgroup$
    – Ben S
    Commented Jun 14, 2016 at 18:15
  • $\begingroup$ You didn't include the value of DiskR, but replacing DiskR with 3/2 seems to give something similar to your last figure. However, I can't reproduce your last result: Area[ RegionIntersection[ Polygon[{{0, 0}, {0, .7}, {-1, 1}}], Disk[{0, 0}, 3/2, {Pi/6, 3 Pi/6}] ] ] returns $0$ as you expected, not $0.7$ as you reported (results). I am using MMA 10.4 on Win7-64. What version are you using? $\endgroup$
    – MarcoB
    Commented Jun 15, 2016 at 17:22

1 Answer 1

4
$\begingroup$

In this case, the intersection between two 2D regions is a 1D region - a line. It makes sense that the functions that are called by RegionMeasure and RegionIntersection might be influenced by roundoff errors associated with using floating point numbers rather than exact numbers.

So a workaround is to convert your expressions to use exact numbers prior to taking the area. I had originally used Rationalize to do this, and it works in this case, but it doesn't always. So we can borrow a function from illian that is a bit more robust

sp = Function[p, SetPrecision[p, Infinity]];    
DiskR = 1.0; 
Area[
 RegionIntersection[sp@Polygon[{{0, 0}, {0, .7}, {-1, 1}}], 
  sp@Disk[{0, 0}, DiskR, {Pi/6, 3 Pi/6}]]]

(* 0 *)

While this behavior is understandable, I'd still say it's a bug

$\endgroup$

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.