Computing the area in a polyline?
This should not be too hard to do in user land -- while you are waiting for the TikZ team, here is a simple Shoelace algorithm done in plain Metapost. Compile with mpost
or adapt for lualatex
with luamplib
.
prologues := 3;
outputtemplate := "%j%c.%{outputformat}";
vardef shoelace_area(expr p) =
for i=1 upto length p:
+ 1/2 xpart point i of p * ypart point i+1 of p
- 1/2 ypart point i of p * xpart point i+1 of p
endfor
enddef;
beginfig(1);
path t; t = for i=0 upto 4: 100 dir 72i -- endfor cycle;
draw origin -- point 1 of t; label.lft(btex $R=100$ etex, 1/2 point 1 of t);
draw t; dotlabel.rt(decimal shoelace_area(t), origin) withcolor 2/3 red;
draw thelabel(btex $\displaystyle A = {5\over4}R^2\sqrt{5+\sqrt5\over2}$ etex, origin) scaled 3/4 shifted 30 down;
draw thelabel(btex $A = 2.37764129 R^2$ etex, origin) scaled 3/4 shifted 54 down;
endfig;
end.
The example figure applies it to a pentagon:
As I have tried to show, this gives you about 6 sig. fig. of accuracy using plain MP's scaled arithmetic, and if you apply it to anything much bigger than this you will get an arithmetic overflow. But if you compile with mpost -numbersystem double
you get an accurate answer and rather less chance of overflow:
Application of Shoelace formula using Tikz library math
. As an example, the complex application in the link specified by @Thruston is taken.
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\usepackage{tkz-euclide}
\tikzmath{
\x1 = 3; \y1 =4;
\x2 = 5; \y2 =11;
\x3 = 12; \y3 =8;
\x4 = 9; \y4 =5;
\x5 = 5; \y5 =6;
\Det = (\x1*\y2) + (\x2*\y3) + (\x3*\y4) + (\x4*\y5) + (\x5*\y1)-
(\x2*\y1) - (\x3*\y2) - (\x4*\y3) - (\x5*\y4) - (\x1*\y5);
\Area = abs (\Det / 2);
}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmax=13,ymax=12,xmin=0,ymin=0]
\tkzGrid
\tkzAxeXY
\draw[fill=gray!30](\x1,\y1)--(\x2,\y2)--(\x3,\y3)--(\x4,\y4)--(\x5,\y5)--cycle;
\tkzText [below](6.5,-1){$A = \Area$} ;
\end{tikzpicture}
\end{document}