Polygon Circle

Regular polygons are called convex and star polygons that cross themselves are non-convex. For both types the vertexes (vertices) are on a circle that has a center and radius.

The turning angle the turtle uses from line to line is more generally called the exterior angle of a polygon. Its the angle from the line extended to the next line.

The sum of the exterior angles of a regular polygon = 360.

nA=360

To find the radius of a regular polygon, divide it into triangles. each wedge has a central angle of 360/n.

Bi-Secting one of these triangles creates a right triangle with a known angle and a known side length.

This formula works for regular polygons and for star polygons. If a line is drawn from the center to each vertex, and a line drawn perpendicular to the edge, right triangles with known sides and angles are created.

now that we have the radius, the center point can be found. Think of the turtle on a vertex, heading turned to the next line. It is on a triangle we already solved to find the radius. we use the same angles. The angle that the turtle needs to turn to look at the center is 90-A/2. I use acad utility polarpoint, not the turtle, to draw the circle. I wrote a new turtle class function to return the current turtle position as a point using a dynamic array and used it directly in PolarPoint.

Sub poly_1(angle As Double, n As Integer, len_side As Double)
Dim inc As Integer
Dim rad As Double
Dim A As Double
Dim ctr() As Double
Dim ang2ctr As Double
Dim acadcirc As acadcircle

A = ang2rad(angle)
rad = len_side / (2 * (Sin(A / 2)))

ang2ctr = ang2rad(turtle1.heading - (angle / 2) + 90)
ctr = acadDoc.Utility.PolarPoint(turtle1.pt1, ang2ctr, rad)

For inc = 1 To n
turtle1.fd len_side
turtle1.left angle
Next inc

Set acadcirc = acadDoc.ModelSpace.AddCircle(ctr, rad)

txt_h "A = " & angle, turtle1.x1, turtle1.y1, 0.125
txt_h "n = " & n, turtle1.x1, turtle1.y1 - 0.25, 0.125
txt_h "R = " & (angle * n / 360), turtle1.x1, turtle1.y1 - 0.5, 0.125
txt_h "Radius = " & Round(rad, 4), turtle1.x1, turtle1.y1 - 0.75, 0.125

End Sub

'this is part of the turtle class module to return current position as a point array
Public Function pt1() As Double()
Dim pnt(0 To 2) As Double
pnt(0) = Me.x1: pnt(1) = Me.y1: pnt(2) = 0
pt1 = pnt
End Function

I am not going to try to draw these triangles, but all the graphics check out, it seems like my formulas derived from simpler polygons gives me the correct center and radius.


Sub turtle_demo_18()
 init_turtle
 Dim n As Integer, R As Integer
 Dim A As Long

 A = 164
 n = LCM(A, 360) / A
 R = LCM(A, 360) / 360
 
 Call poly_1(CDbl(A), n, 1)
End Sub

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.