Trigonometry in Pov-Ray

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:

Example


  1. Returns the length between the center of the polygon and the center of one side (apothem).
  2. Returns the distance between the center and one of the vertices (radio).
  3. Returns length of the segment vertex-center_side (L/2).
  4. Returns in degrees the central angle 360/N_sides (vertex, center, vertex).
  5. Returns in degrees the half of central angle 180/N_sides (vertex, center, center_side).
  6. Returns in degrees the angle center-vertex-center_side.
  7. Returns in degrees the interior angle formed by two sides of the polygon.
  8. Returns in degrees the exterior angle formed by two sides of the polygon.
  9. Returns height of the polygon.
  10. Returns the major diagonal between opposite corners of a pair sided polygon.
  11. Returns perimeter
  12. Returns area
  13. 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

 

 
This entry was posted in Macros and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>