One of my worst vices in math has always been having to rethink and rewrite the same formulas in different scenes for simple math calculations in POV-Ray. See here, a simple macro to calculate angles, sides and areas of regular polygons.
Depending on your choice the macro returns one of the following values in a polygon of N sides and side L:
- Returns the length between the center of the polygon and the center of one side (apothem).
- Returns the distance between the center and one of the vertices (radio).
- Returns length of the segment vertex-center_side (L/2).
- Returns in degrees the central angle 360/N_sides (vertex, center, vertex).
- Returns in degrees the half of central angle 180/N_sides (vertex, center, center_side).
- Returns in degrees the angle center-vertex-center_side.
- Returns in degrees the interior angle formed by two sides of the polygon.
- Returns in degrees the exterior angle formed by two sides of the polygon.
- Returns height of the polygon.
- Returns the major diagonal between opposite corners of a pair sided polygon.
- Returns perimeter
- Returns area
- Returns lower diagonal.
#macro Trigon(N,L,D) #switch (D) #case (1) #local Valor = (L/2) / tand(180/N) ; #break #case (2) #local Valor = (L/2) / sind(180/N) ; #break #case (3) #local Valor = (L/2) ; #break #case (4) #local Valor = 360/N ; #break #case (5) #local Valor = 180/N ; #break #case (6) #local Valor = (90-(180/N)) ; #break #case (7) #local Valor = (90-(180/N))*2 ; #break #case (8) #local Valor = 360-Trigon(N,L,5) ; #break #case (9) #if (odd(N)=true) #local Valor = Trigon(N,L,1)+Trigon(N,L,2) ; #else #local Valor = Trigon(N,L,1)*2; #end #break #case (10) #local Valor = Trigon(N,L,2)*2 ; #break #case (11) #local Valor = L*N ; #break #case (12) #local Valor = N*((L/2)*Trigon(N,L,1)); #break #case (13) #local Valor = 2*((L/2)/sind(180/N))*sin(360/N); #break #end Valor #end


