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
Click For Summary
The discussion revolves around using Visual Basic to plot a circle in a two-dimensional array. Initially, the user demonstrates how to fill a 2D array with ones to create a square. They then explore using the Pythagorean theorem to plot a circle by calculating the radius and generating points based on the equation of a circle. However, they encounter issues with continuity on the circumference as the y-values approach zero. The user references the Midpoint Circle Algorithm for improvement and successfully implements a method to create a perfect circle by utilizing symmetry and mirroring points. The final code effectively draws a circle by iterating through the bitmap and using graphical functions to render the shape. The user expresses a desire to further explore the algorithm for additional learning.
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?
 
Technology 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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 10 ·
Replies
10
Views
26K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
4
Views
5K
  • · Replies 21 ·
Replies
21
Views
3K