5
$\begingroup$

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?

$\endgroup$
13
$\begingroup$

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
]
*)

2D graphical representation of the above Piecewise function


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
]
*)

2D representation of the Piecewise area for two triangles

$\endgroup$
8
  • $\begingroup$ 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$? $\endgroup$ – Machinato Dec 15 '20 at 7:52
  • 1
    $\begingroup$ you could try GenerateConditions -> All $\endgroup$ – halmir Dec 15 '20 at 16:33
  • $\begingroup$ @MarcoB, for two parameters a,b, and a triangle region, it will show no output. $\endgroup$ – Machinato Dec 16 '20 at 19:18
  • $\begingroup$ @Machinato Take a look at the updated version. $\endgroup$ – MarcoB Dec 16 '20 at 23:13
  • $\begingroup$ @halmir That's a great idea! $\endgroup$ – MarcoB Dec 16 '20 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.