[bb] Polygon Inscribed Inside Circle by blade007 [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

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
Graphics 800,600,32,2

DrawInscribedPolygon(3,100,170,150,30)
Text 170,150,"Triangle",True,True
DrawInscribedPolygon(6,100,370,400,0)
Text 370,400,"Hexagon",True,True
DrawInscribedPolygon(8,100,580,150,0)
Text 580,150,"Octagon",True,True

WaitKey

Function 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 BeginLoop
End Function


Code :
Code (blitzbasic) Select
Function 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 BeginLoop
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

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.