Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Circles in visual basic

  1. Sep 20, 2012 #1
    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?
     
  2. jcsd
  3. Sep 25, 2012 #2
    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. Sep 25, 2012 #3
  5. Sep 25, 2012 #4
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Circles in visual basic
  1. Fortran / Visual Basic ? (Replies: 13)

Loading...