# Exact symbolic area of an intersection of two polygons with parameters

On the one hand, can handle expressions which include parameters, including polygons, for example:

Area[Polygon[{{1, 2}, {-1, 1}, {2, 5}, {1, a}}]]


returns

1/2 Abs[-7 + a]


On the other hand, RegionIntersection breaks the symbolic evaluation. Consider a minimal example:

Area[
RegionIntersection[
Polygon[{{1, 2}, {-1, 1}, {2, 5}}],
Polygon[{{2, 4}, {1, -3}, {1, a}}]
]
]


Clearly, this is equal to some piecewise function of $$a$$. However, $$0$$ is returned. How to force Mathematica to give a function of $$a$$ as a result?

Having Area generate conditions is informative:

Area[
RegionIntersection[
Polygon[{{1, 2}, {-1, 1}, {2, 5}}],
Polygon[{{2, 4}, {1, -3}, {1, a}}]
],
GenerateConditions -> True
]

(* Out: ConditionalExpression[0, a < 2] *)


Indeed, for $$a<2$$ there is no intersection, so the area of the intersection is correctly $$0$$.

On the one hand, we can try to feed an assumption to Area that $$a>2$$:

Area[
RegionIntersection[
Polygon[{{1, 2}, {-1, 1}, {2, 5}}],
Polygon[{{2, 4}, {1, -3}, {1, a}}]
],
Assumptions -> a > 2
]

(* Out: (5*(5 - 11*a + 3*a^2))/(6*(-1 + a)*(-8 + 3*a)) *)


That area is now expressed as a function of $$a$$ as desired.

More generally, we can use GenerateConditions -> All:

Area[
RegionIntersection[
Polygon[{{1, 2}, {-1, 1}, {2, 5}}],
Polygon[{{2, 4}, {1, -3}, {1, a}}]
],
GenerateConditions -> All
]

(* Out:
Piecewise[{
{(4 - 4*a + a^2)/(2*(-1 + a)),                   2 <= a <= 11/3},
{(5*(5 - 11*a + 3*a^2))/(6*(-1 + a)*(-8 + 3*a)), a > 11/3}},
0
]
*)


This also works for multiple parameters. For the example mentioned in comments of two-parameter triangular regions:

Area[
RegionIntersection[
Triangle[{{0, 0}, {1, 0}, {a, b}}],
Triangle[{{0, 0}, {1, 0}, {0, 1}}]
],
GenerateConditions -> All
]

(* Out:
Piecewise[{
{1/2,               a <= 0 && a + b > 1},
{b/2,               0 < a <=1 && b > 0 && a + b <= 1},
{-(b/(2*(-1 + a))), a <= 0 && b > 0 && a + b <= 1},
{b/(2*(a + b)),    (0 < a <= 1 && a + b > 1) || (a > 1 && b > 0)}},
0
]
*)


• Thank you for this answer. It is possible to generalize this method if there are two parameters $a,b$ in the definition of polygons instead of just $a$? Commented Dec 15, 2020 at 7:52
• you could try GenerateConditions -> All Commented Dec 15, 2020 at 16:33
• @MarcoB, for two parameters a,b, and a triangle region, it will show no output. Commented Dec 16, 2020 at 19:18
• @Machinato Take a look at the updated version. Commented Dec 16, 2020 at 23:13
• @halmir That's a great idea! Commented Dec 16, 2020 at 23:13