Perimeter, area and visualization of a plane figure
Dr. Yury Zavarovsky
Penza branch of the Financial University
under the Government of the Russian Federation
![Given a figure in the plane bounded by the non-selfintersecting piecewise smooth curve. Each segment in the border defined by the list in the following format (variable names in expressions can be arbitrary): 1) If this segment is given by an explicit equation, then [f(x), x=x1..x2)] 2) If it is given in polar coordinates, then [f(phi), phi=phi1..phi2, polar] , phi is polar angle 3) If the segment is given parametrically, then [[f(t), g(t)], t=t1..t2] 4) If several consecutive segments or entire border is a broken line, then it is sufficient to set vertices the broken line [ [x1,y1], [x2,y2], .., xn..yn]] The first procedure symbolically finds perimeter of the figure. Global variable Q saves the lengths of all segments.](/view.aspx?SI=146470/d45b99305d02d10b5612251c791bc7fc.gif)
Procedure 1. Perimeter of a plane figure
![Perimeter := proc (L) local i, var, var1, var2, e, e1, e2, P; global Q; for i to nops(L) do if type(L[i], listlist(algebraic)) then P[i] := seq(simplify(sqrt((L[i, j, 1]-L[i, j+1, 1])^2+(L[i, j, 2]-L[i, j+1, 2])^2)), j = 1 .. nops(L[i])-1) else var := lhs(L[i, 2]); var1 := min(lhs(rhs(L[i, 2])), rhs(rhs(L[i, 2]))); var2 := max(lhs(rhs(L[i, 2])), rhs(rhs(L[i, 2]))); if type(L[i, 1], algebraic) then e := L[i, 1]; if nops(L[i]) = 3 then P[i] := simplify(int(sqrt(e^2+(diff(e, var))^2), var = var1 .. var2)) else P[i] := simplify(int(sqrt(1+(diff(e, var))^2), var = var1 .. var2)) end if else e1 := L[i, 1, 1]; e2 := L[i, 1, 2]; P[i] := abs(simplify(int(sqrt((diff(e1, var))^2+(diff(e2, var))^2), var = var1 .. var2))) end if end if end do; Q := [seq(P[i], i = 1 .. nops(L))]; add(Q[i], i = 1 .. nops(Q)) end proc](/view.aspx?SI=146470/69c937b50a03d9f01aca06917804e938.gif)

Procedure 2. Area of a plane figure
![Area := proc (L) local i, var, e, e1, e2, P; for i to nops(L) do if type(L[i], listlist(algebraic)) then P[i] := (1/2)*add(L[i, j, 1]*L[i, j+1, 2]-L[i, j, 2]*L[i, j+1, 1], j = 1 .. nops(L[i])-1) else var := lhs(L[i, 2]); if type(L[i, 1], algebraic) then e := L[i, 1]; if nops(L[i]) = 3 then P[i] := (1/2)*(int(e^2, L[i, 2])) else P[i] := (1/2)*simplify(int(var*(diff(e, var))-e, L[i, 2])) end if else e1 := L[i, 1, 1]; e2 := L[i, 1, 2]; P[i] := (1/2)*simplify(int(e1*(diff(e2, var))-e2*(diff(e1, var)), L[i, 2])) end if end if end do; abs(add(P[i], i = 1 .. nops(L))) end proc](/view.aspx?SI=146470/85a0894ae2608ca39603e033071f3f20.gif)
The third procedure shows this figure. To paint the interior of the boundary polyline approximation is used. Required parameters: L - a list of all segments of the border and C - the color of the interior of the figure in the format color = color of the figure. Optional parameters: N - the number of parts for the approximation of each segment (default N = 100) and Boundary is defined by a list for special design of the figure's border (the default border is drawed by a thin black line). The border of the figure can be drawn separately without filling the interior by the global variable Border.

![Picture := proc (L, C, N::posint := 100, Boundary::list := [linestyle = 1]) local i, var, var1, var2, e, e1, e2, P, Q, h; global Border; for i to nops(L) do if type(L[i], listlist(algebraic)) then P[i] := op(L[i]) else var := lhs(L[i, 2]); var1 := lhs(rhs(L[i, 2])); var2 := rhs(rhs(L[i, 2])); h := (var2-var1)/N; if type(L[i, 1], algebraic) then e := L[i, 1]; if nops(L[i]) = 3 then P[i] := seq(subs(var = var1+h*i, [e*cos(var), e*sin(var)]), i = 0 .. N) else P[i] := seq([var1+h*i, subs(var = var1+h*i, e)], i = 0 .. N) end if else e1 := L[i, 1, 1]; e2 := L[i, 1, 2]; P[i] := seq(subs(var = var1+h*i, [e1, e2]), i = 0 .. N) end if end if end do; Q := [seq(P[i], i = 1 .. nops(L))]; Border := plottools[curve]([op(Q), Q[1]], op(Boundary)); [plottools[polygon](Q, C), Border] end proc](/view.aspx?SI=146470/40ecead70ba6b431c18dc37688aa8dbd.gif)
Examples of working
Example 1
![L := [[sqrt(-x), x = -1 .. 0], [2*cos(t), t = -(1/2)*Pi .. (1/4)*Pi, polar], [[1, 1], [1/2, 0], [0, 3/2]], [[-1+cos(t), 3/2+(1/2)*sin(t)], t = 0 .. -(1/2)*Pi]]; Perimeter(L); Q; evalf(`%%`); evalf(`%%`); Area(L)](/view.aspx?SI=146470/80d7f1f576d009d903a1e34b33cbb128.gif)
| (1) |
, scaling = constrained); plots[display](Border, scaling = constrained)](/view.aspx?SI=146470/ed684606168e5a6c2a3da7a8ab652918.gif)
Example 2
)](/view.aspx?SI=146470/03473460a1328ce0fbf5e05629943e45.gif)
Example 3
![2*2^(1/2)*EllipticE((1/2)*2^(1/2), (1/2)*2^(1/2))+2*2^(1/2)*EllipticE((1/2)*2^(1/2)), [2*2^(1/2)*EllipticE((1/2)*2^(1/2), (1/2)*2^(1/2)), 2^(1/2)*EllipticE((1/2)*2^(1/2), (1/2)*2^(1/2)), 2*2^(1/2)*EllipticE((1/2)*2^(1/2))-2^(1/2)*EllipticE((1/2)*2^(1/2), (1/2)*2^(1/2))]](/view.aspx?SI=146470/3ddb5f038f63ed4f3407cc914786a674.gif)
| (2) |
| (3) |
| (4) |
, cos(x), -cos(x)], x = -(1/3)*Pi .. 11*Pi*(1/6), color = black)); B := Picture(L, color = cyan, [thickness = 3]); plots[display](A, B, scaling = constrained)](/view.aspx?SI=146470/33b98a7e6ef9c676ad532b7d3953603c.gif)
Example 4
![[0, 1], [-(1/4)*2^(1/2)*(5+5^(1/2))^(1/2), (1/4)*5^(1/2)-1/4], [-(1/4)*2^(1/2)*(5-5^(1/2))^(1/2), -(1/4)*5^(1/2)-1/4], [(1/4)*2^(1/2)*(5-5^(1/2))^(1/2), -(1/4)*5^(1/2)-1/4], [(1/4)*2^(1/2)*(5+5^(1/2))^(1/2), (1/4)*5^(1/2)-1/4]](/view.aspx?SI=146470/86bc05eb1950c3711d296e744ad9f202.gif)
| (5) |

| (6) |
| (7) |
| (8) |
![G, H, K, M, P := op(expand([seq(convert([r*cos(-(1/2)*Pi+2*Pi*k*(1/5)), r*sin(-(1/2)*Pi+2*Pi*k*(1/5))], radical), k = 0 .. 4)]))](/view.aspx?SI=146470/11202980436a492906e3215c9c891a37.gif)
![[0, -3/2+(1/2)*5^(1/2)], [(3/8)*2^(1/2)*(5+5^(1/2))^(1/2)-(1/8)*5^(1/2)*2^(1/2)*(5+5^(1/2))^(1/2), -(1/2)*5^(1/2)+1], [(3/8)*2^(1/2)*(5-5^(1/2))^(1/2)-(1/8)*2^(1/2)*5^(1/2)*(5-5^(1/2))^(1/2), (1/4)*5^(1/2)-1/4], [-(3/8)*2^(1/2)*(5-5^(1/2))^(1/2)+(1/8)*2^(1/2)*5^(1/2)*(5-5^(1/2))^(1/2), (1/4)*5^(1/2)-1/4], [-(3/8)*2^(1/2)*(5+5^(1/2))^(1/2)+(1/8)*5^(1/2)*2^(1/2)*(5+5^(1/2))^(1/2), -(1/2)*5^(1/2)+1]](/view.aspx?SI=146470/f6376b5ada5021b7ef357716d4bb5bc5.gif)
| (9) |
![[[[0, 1], [-(3/8)*2^(1/2)*(5-5^(1/2))^(1/2)+(1/8)*2^(1/2)*5^(1/2)*(5-5^(1/2))^(1/2), (1/4)*5^(1/2)-1/4], [-(1/4)*2^(1/2)*(5+5^(1/2))^(1/2), (1/4)*5^(1/2)-1/4], [-(3/8)*2^(1/2)*(5+5^(1/2))^(1/2)+(1/8)*5^(1/2)*2^(1/2)*(5+5^(1/2))^(1/2), -(1/2)*5^(1/2)+1], [-(1/4)*2^(1/2)*(5-5^(1/2))^(1/2), -(1/4)*5^(1/2)-1/4], [0, -3/2+(1/2)*5^(1/2)], [(1/4)*2^(1/2)*(5-5^(1/2))^(1/2), -(1/4)*5^(1/2)-1/4], [(3/8)*2^(1/2)*(5+5^(1/2))^(1/2)-(1/8)*5^(1/2)*2^(1/2)*(5+5^(1/2))^(1/2), -(1/2)*5^(1/2)+1], [(1/4)*2^(1/2)*(5+5^(1/2))^(1/2), (1/4)*5^(1/2)-1/4], [(3/8)*2^(1/2)*(5-5^(1/2))^(1/2)-(1/8)*2^(1/2)*5^(1/2)*(5-5^(1/2))^(1/2), (1/4)*5^(1/2)-1/4]]]](/view.aspx?SI=146470/733ecb0cccb79a0704ffdce6e95b371f.gif)
| (10) |
, scaling = constrained); Perimeter = Perimeter(L); Approximation = evalf(rhs(%)); Area = Area(L); Approximation = evalf(rhs(%))](/view.aspx?SI=146470/6d9ad197283a72308c40d68d9e98223e.gif)
| (11) |
Example 5 is more complicated .
3 circles on the plane C1, C2 and C3 defined by the parametric equations of their borders. We want to find the perimeter, area, and paint the figure C3 minus (C1 union C2) .
Example 5

![sol1 := simplify(allvalues(solve({rhs(C1[1]) = rhs(C3[1]), rhs(C1[2]) = rhs(C3[2])}, {t, u})))](/view.aspx?SI=146470/4532c9195b5fad249e3837cdc7eb7fe2.gif)
| (12) |
| (13) |
![sol2 := simplify([allvalues(solve({rhs(C1[1]) = rhs(C2[1]), rhs(C1[2]) = rhs(C2[2])}, {s, t}))])](/view.aspx?SI=146470/6dfb0ccd06a4ba300e2a4a4150540570.gif)
![[{s = -arctan((1/3)*(9+7^(1/2)*55^(1/2))/(-7^(1/2)+55^(1/2))), t = -arctan(3*(-23+7^(1/2)*55^(1/2))/(23*7^(1/2)+9*55^(1/2)))}, {s = -arctan((1/3)*(-9+7^(1/2)*55^(1/2))/(7^(1/2)+55^(1/2)))+Pi, t = -arctan(3*(23+7^(1/2)*55^(1/2))/(-23*7^(1/2)+9*55^(1/2)))+Pi}]](/view.aspx?SI=146470/37a18b1cbd1bee53371e26d4dd67dedc.gif)
| (14) |
| (15) |
![sol3 := simplify([allvalues(solve({rhs(C3[1]) = rhs(C2[1]), rhs(C3[2]) = rhs(C2[2])}, {s, u}))])](/view.aspx?SI=146470/e91ae952ae5cf1aea93ebe4b9949714c.gif)
![[{s = arctan((1/3)*(-9+4*91^(1/2))/(4+91^(1/2))), u = arctan(3*(41+4*91^(1/2))/(-164+9*91^(1/2)))+Pi}, {s = arctan((1/3)*(9+4*91^(1/2))/(-4+91^(1/2)))-Pi, u = arctan(3*(-41+4*91^(1/2))/(164+9*91^(1/2)))+Pi}]](/view.aspx?SI=146470/ccc89ec68f20a3a167a4014ca8a586f5.gif)
| (16) |
| (17) |
![L := [[[rhs(C1[1]), rhs(C1[2])], t = t1 .. t2], [[rhs(C2[1]), rhs(C2[2])], s = s1 .. s2], [[rhs(C3[1]), rhs(C3[2])], u = u2 .. u1]]](/view.aspx?SI=146470/e12d619b07bb77a24aa29afda3118715.gif)
![[[[-7^(1/2)+4*cos(t), 4*sin(t)], t = -arccos((1/4)*(7+4*7^(1/2))/(7^(1/2)+4)) .. -arctan(3*(-23+7^(1/2)*55^(1/2))/(23*7^(1/2)+9*55^(1/2)))], [[3*cos(s), 3+3*sin(s)], s = -arctan((1/3)*(9+7^(1/2)*55^(1/2))/(-7^(1/2)+55^(1/2))) .. arctan((1/3)*(-9+4*91^(1/2))/(4+91^(1/2)))], [[4+5*cos(u), 5*sin(u)], u = arctan(3*(41+4*91^(1/2))/(-164+9*91^(1/2)))+Pi .. arctan(3/4)-Pi]]](/view.aspx?SI=146470/ab7f1cbdd60856d2b3f104d2e66dc315.gif)
| (18) |
![4*arccos((1/4)*(7+4*7^(1/2))/(7^(1/2)+4))-4*arctan(3*(-23+7^(1/2)*55^(1/2))/(23*7^(1/2)+9*55^(1/2)))+3*arctan(3*(36+9*7^(1/2)*13^(1/2)+4*7^(1/2)*55^(1/2)+7*55^(1/2)*13^(1/2)+9*7^(1/2)-9*55^(1/2)-28*13^(1/2)+4*55^(1/2)*7^(1/2)*13^(1/2))/(-36*7^(1/2)-63*13^(1/2)+36*55^(1/2)+9*55^(1/2)*7^(1/2)*13^(1/2)+81-36*7^(1/2)*13^(1/2)+9*7^(1/2)*55^(1/2)-28*55^(1/2)*13^(1/2)))+8*Pi+5*arctan(3*(328+7*91^(1/2))/(72*91^(1/2)-287)), [4*arccos((1/4)*(7+4*7^(1/2))/(7^(1/2)+4))-4*arctan(3*(-23+7^(1/2)*55^(1/2))/(23*7^(1/2)+9*55^(1/2))), 3*arctan(3*(36+9*7^(1/2)*13^(1/2)+4*7^(1/2)*55^(1/2)+7*55^(1/2)*13^(1/2)+9*7^(1/2)-9*55^(1/2)-28*13^(1/2)+4*55^(1/2)*7^(1/2)*13^(1/2))/(-36*7^(1/2)-63*13^(1/2)+36*55^(1/2)+9*55^(1/2)*7^(1/2)*13^(1/2)+81-36*7^(1/2)*13^(1/2)+9*7^(1/2)*55^(1/2)-28*55^(1/2)*13^(1/2)))+3*Pi, 5*arctan(3*(328+7*91^(1/2))/(72*91^(1/2)-287))+5*Pi]](/view.aspx?SI=146470/5dc03c5d8a3622bf6c1d2137d210142f.gif)
| (19) |
| (20) |
| (21) |
![A := plot([[rhs(C1[1]), rhs(C1[2]), t = 0 .. 2*Pi], [rhs(C2[1]), rhs(C2[2]), s = 0 .. 2*Pi], [rhs(C3[1]), rhs(C3[2]), u = 0 .. 2*Pi]], color = black)](/view.aspx?SI=146470/7a78a9626fa059e7a7c10207655e3b28.gif)
![B := Picture(L, color = green, [color = black, thickness = 4]); plots[display](A, B, scaling = constrained)](/view.aspx?SI=146470/2fcb0c1dc27aa8ac7347b3ac3fddd987.gif)
|