I want to integrate a function f[x,y]
over a region like this.
Is there any way to define the region using the vertices of the purple polygon?
Then I can subsequently perform NIntegrate[f[x,y],{x, y} ∈ region]
Here is an example in 12.2.
poly = Polygon[{{0, 0}, {1/2, Sqrt[3]/2}, {1, 1/Sqrt[3]}, {1, 0}}];
NIntegrate[Log[x + y + 1], {x, y} \[Element] poly]
0.366623
Let us verify it by
Integrate[Log[x + y + 1], {x, y} \[Element] poly]
-((36 - 12 Sqrt[3] + 12 Log[2] + 228 Sqrt[3] Log[2] + 138 Log[3] + 54 Sqrt[3] Log[3] + 9 Log[4] - 3 Sqrt[3] Log[4] + 48 Sqrt[3] Log[6] - 2 Log[8] - 2 Sqrt[3] Log[8] + 2 Sqrt[3] Log[9] - 48 Sqrt[3] Log[2 - 2/Sqrt[3]] + 90 Log[2 - Sqrt[3]] + 54 Sqrt[3] Log[2 - Sqrt[3]] - 90 Log[3 - Sqrt[3]] - 54 Sqrt[3] Log[3 - Sqrt[3]] - 180 Log[-1 + Sqrt[3]] - 108 Sqrt[3] Log[-1 + Sqrt[3]] + 72 Log[1 + Sqrt[3]] - 48 Sqrt[3] Log[1 + Sqrt[3]] - 36 Log[2 + Sqrt[3]] + 24 Sqrt[3] Log[2 + Sqrt[3]] - 18 Log[3 + Sqrt[3]] - 90 Sqrt[3] Log[3 + Sqrt[3]] - 48 Log[6 + Sqrt[3]] - 52 Sqrt[3] Log[6 + Sqrt[3]] - 72 Log[3 + 2 Sqrt[3]] + 48 Sqrt[3] Log[3 + 2 Sqrt[3]] + 36 Log[9 + 5 Sqrt[3]] - 24 Sqrt[3] Log[9 + 5 Sqrt[3]])/(8 Sqrt[ 3] (19 + 11 Sqrt[3]) (-45 + 26 Sqrt[3])))
N[%]
0.366623
Addition. NIntegrate
produces [a different] the same result if the vertices are taken couunter-clockwise as
poly1 = Polygon[{{1, 1/Sqrt[3]}, {1/2, Sqrt[3]/2}, {0, 0}, {1, 0}}];
NIntegrate[Log[x + y + 1], {x, y} \[Element] poly1]
[
0.17812
]0.366623
shows.
Polygon[]
in clockwise or counter-clockwise manner?
$\endgroup$
Commented
Apr 1, 2021 at 5:18
poly1
and poly
$\endgroup$
Commented
Apr 1, 2021 at 7:16