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
AI Thread 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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
I am trying to run an .ipynb file and have installed Miniconda as well as created an environment as such -conda create -n <env_name> python=3.7 ipykernel jupyter I am assuming this is successful as I can activate this environment via the anaconda prompt and following command -conda activate <env_name> Then I downloaded and installed VS code and I am trying to edit an .ipynb file. I want to select a kernel, via VS Code but when I press the button on the upper right corner I am greeted...

Similar threads

Back
Top