Qbasicnews.com
circle algorithm question - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: circle algorithm question (/thread-9527.html)



circle algorithm question - Agamemnus - 07-17-2006

Let's say I have a circle. The center has (x, y) coordinates (0, 0).

How do I determine the (x, y) coordinates of n points around the circumference of the circle spaced equally apart (along the circumference), assuming we start at a point (0, r), r being the radius?

Thanks....


circle algorithm question - Zap - 07-17-2006

Like this?

Code:
#define PI 3.141592

dim as double radians
dim as integer cx, cy, r, numPoints, px, py

screen 14

cx=150
cy=120
r=100
numPoints=10

for radians=0 to PI*2 step PI*2/numPoints
    px=cx+cos(radians)*r
    py=cy-sin(radians)*r
    pset(px,py)
    'or save coordinates here
    'subtract cx and cy from px and py respectively to get
    'coordinates relatively from (0, 0)
next radians

sleep



circle algorithm question - TheAdventMaster - 07-17-2006

This (basically the same as Zap's heheh)?

Code:
#define PI 3.141592

dim as double radians
dim as integer angle, r, px, py

screenres 640, 480

angle = 30
r=100
numPoints=10

Do
    
    radians = angle * 3.14/180

    px = r * cos(radians)
    py = r * sin(radians)
    
    Line (320, 240)-(320 + px, 240 + py)
    
    Print PX, PY
    
    Angle += 30
    
Loop until angle > 360
sleep



circle algorithm question - Agamemnus - 07-17-2006

Thanks guys!

I needed this for a custom scenario in a Microsoft game called Rise of Legends, btw.