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

Discussion Overview

The discussion revolves around plotting a perfect circle in a 2D array using Visual Basic. Participants explore different methods and algorithms to achieve this, focusing on mathematical approaches and programming techniques.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant shares a basic method for plotting points in a 2D array but seeks a way to create a circular shape.
  • Another participant proposes using the Pythagorean theorem to calculate points on the circumference of a circle, noting that the method does not yield a continuous line as y approaches zero.
  • A third participant references the Midpoint Circle Algorithm as a potential solution for generating a circle.
  • The second participant expresses gratitude for the link and discusses how to implement a mirror image technique to improve the circle's appearance, ultimately achieving a perfect circle.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method initially, but one participant successfully implements a solution based on the discussed techniques. The discussion includes various approaches without resolving which is superior.

Contextual Notes

Some methods discussed may depend on specific definitions of "perfect circle" and the limitations of the array size. The implementation details of the Midpoint Circle Algorithm are not fully explored.

Who May Find This Useful

Individuals interested in programming with Visual Basic, particularly those looking to understand graphical representations and mathematical plotting techniques.

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.
 

Similar threads

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