Circles in visual basic

  • Thread starter derek101
  • Start date
  • #1
22
0

Main Question or Discussion Point

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?
 

Answers and Replies

  • #2
22
0
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 x


only problem is this does not give a continuous line of points on the circumference as y gets close to zero.
would appreciate better idea?
 
  • #4
22
0
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)=1


for 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 y


Now I get a perfect circle.
I shall study the link some more see what else I can learn.THANKS.
 

Related Threads on Circles in visual basic

Replies
5
Views
6K
  • Last Post
Replies
1
Views
988
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
13
Views
3K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
1
Views
485
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
1
Views
2K
Top