January 20, 2021, 10:21:05 AM

### Author Topic: [bb] Polygon Inscribed Inside Circle by blade007 [ 1+ years ago ]  (Read 1650 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Polygon Inscribed Inside Circle by blade007 [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : Polygon Inscribed Inside Circle
Author : blade007
Posted : 1+ years ago

Description : Parameters:
Sides - The number of sides the inscribed angle contains
Radius - The distance from the center of the circle to the edge
CenterX and CenterY - The corridnates of the center of the circle
Rotate# - Rotates the polygon in degrees

example code
Code: [Select]
`Graphics 800,600,32,2DrawInscribedPolygon(3,100,170,150,30)Text 170,150,"Triangle",True,TrueDrawInscribedPolygon(6,100,370,400,0)Text 370,400,"Hexagon",True,TrueDrawInscribedPolygon(8,100,580,150,0)Text 580,150,"Octagon",True,TrueWaitKeyFunction DrawInscribedPolygon(Sides,Radius,CenterX,CenterY,Rotate#) PerAngle# = 360/Float(Sides) Angle# = Rotate# OriginPoint = True .BeginLoop ; I use a goto loop because the step value was not constant PrevX = cVertexX PrevY = cVertexY cVertexX = (CenterX+Radius*Cos(Angle#)) cVertexY = (CenterY+Radius*Sin(Angle#)) If OriginPoint = False Then Line PrevX,PrevY,cVertexX,cVertexY Else OriginPoint = False Angle# = Angle# + PerAngle# If Angle# < 360.1+Rotate# Then Goto BeginLoopEnd Function`

Code :
Code: BlitzBasic
1. Function DrawInscribedPolygon(Sides,Radius,CenterX,CenterY,Rotate#)
2.         PerAngle# = 360/Float(Sides)
3.         Angle# = Rotate#
4.         OriginPoint = True
5.         .BeginLoop ; I use a goto loop because the step value was not constant
6.                 PrevX = cVertexX
7.                 PrevY = cVertexY
8.                 cVertexX = (CenterX+Radius*Cos(Angle#))
9.                 cVertexY = (CenterY+Radius*Sin(Angle#))
10.                 If OriginPoint = False Then Line PrevX,PrevY,cVertexX,cVertexY Else OriginPoint = False
11.                 Angle# = Angle# + PerAngle#
12.         If Angle# < 360.1+Rotate# Then Goto BeginLoop
13. End Function

Comments :

schilcote(Posted 1+ years ago)

You could've used a while loop instead of a goto loop, but I guess that dosn't really matter.

#### windman

• Jr. Member
• Posts: 30
##### Polygon Inscribed Inside Circle by blade007 [ 1+ years ago ]
« Reply #1 on: February 11, 2019, 10:17:56 PM »
Very Nice Job

Code of this nature should be ported to 3D as well since it would make the best visual use of the compilers functions.

SimplePortal 2.3.6 © 2008-2014, SimplePortal