How can I plot a perfect circle in a 2D array using Visual Basic?

  • Thread starter Thread starter derek101
  • Start date Start date
  • Tags Tags
    Circles Visual
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 2K views
derek101
Messages
22
Reaction score
0
hi,I am learning visual basic as a pastime.
I have a question,I can plot positions in a 2 dimensional array e.g:-
dim test(100,100) as integer
for cox as integer = 40 to 60
for coy as integer = 40 to 60
test(cox,coy)=1
next cox
next coy

My question is how can I plot positions to make a circle of 1's in my array?
 
Physics news on Phys.org
ah sussed it I can use Pythagoras.

dim bitmap(400,400) as integer
radius=100
z=radius*radius
for x=0 to radius
t=x*x
d=z-t
y=d^(1/2)
bitmap(200+x,200-y)=1
bitmap(200+x,200+y)=1
bitmap(200-x,200-y)=1
bitmap(200-x,200+y)=1
next xonly problem is this does not give a continuous line of points on the circumference as y gets close to zero.
would appreciate better idea?
 
ok thanks for link.

not quiet sure how I use the algorithm,but see I can make mirror image.

bitmap(200+x,200-y)=1
bitmap(200+x,200+y)=1
bitmap(200-x,200-y)=1
bitmap(200-x,200+y)=1
plus mirror image
bitmap(200+y,200-x)=1
bitmap(200+y,200+x)=1
bitmap(200-y,200-x)=1
bitmap(200-y,200+x)=1for x = 0 to 399
for y = 0 to 399
if bitmap(x,y) = 1 then g.drawline(bluepen,x+100,y+100,x+101,y+100)
next x
next yNow I get a perfect circle.
I shall study the link some more see what else I can learn.THANKS.