Calculating pi by counting pixels (area method)
Вставка
- Опубліковано 4 кві 2023
- In last week's video, I wrote a program to calculate pi by drawing the outline of a circle and estimating the circumference by counting pixels. This is not the right method, and I explained that in the video.
I said it was because the outline is "sampling" the circle - but that' not right. I'll refer you to a very well done video from 3 blue 1 brown about why this doesn't work. It's the second of the "false proofs" he demonstrates:
• How to lie using visua...
A better way to calculate pi by counting pixels is with the Area. And that's our updated video for this week.
Visit our website
www.freedos.org/
Join us on Facebook
/ freedosproject
Follow us on Mastodon
fosstodon.org/@freedosproject
Consider supporting me on Patreon
/ freedos
And don't forget to Like and Subscribe!
Standard comment rules apply. - Наука та технологія
Super cool! I never know what to expect from this channel but it's always interesting.
Glad you enjoy it! :-)
Hell yeah! I just watched all videos on that channel, and now I'm officially FreeDOS master fan!
Thanks! I'm glad you like the channel. It's been a few weeks since I posted videos, but more are coming soon!
Simple refactoring returns a much closer result,
That was fantastic, more videos please.
Thanks Jim,
Thanks, will do!
Very good! Would it be wrong to say that with such calculations, an increase in resolution will have a positive effect on the accuracy of the calculation?
It might!
This method doesn't use the first principals to estimate Pi. There is no intuitive way to claim the area of the circle is Pi x r².
Well, this method isn't really meant to be a math proof. When you look at it, this is a backwards proof. We're using a graphics function to draw a filled-in circle for us, then counting the pixels in that circle to estimate area, so we can calculate pi. The graphics function already has to use pi to draw the circle anyway.
I love the circle videos I'm always learning something new from your c videos for example I NEVER knew that you can make a program that can count PIXELS!?
You are so welcome!
Have you tested if your program runs faster if you do the for loop of x inside of the y loop?
I ask because as far as i know, the videocard does do the drawing like a CRT from the top left to the top right and then that in a loop from top to bottom. The internal arrays used for the drawing routines of the Watcom C compiler might take that into account thus it could be faster by walking first through the x values, then the y values.
I can't see how this would help. In the nested loops, I'm changing individual pixels. Screen refresh isn't a factor.
@@freedosproject Yes, but if i remember correctly the horizontal pixels are aligned in the VRAM in a way, that they are filled first, then the next row. For that a simple increment of a loop should be enough. Doing it vertically means that you have to jump around in the VRAM which means the calculation of memory addresses instead of a simple increment to the next memory address.
Is it in FreeDOS possible to temporarily change the language?
I tried to change the COUNTRY statement in FDCONFIG sys.
And the
SET LANG variable in FDAUTO bat.
But this wasn't enough. The messages from freecom_lng where still in my native language, not the language i wanted to have.
I found the error. It seems to be, that FreeCOM doesn't use the FREECOM_LNG files. Instead it uses precompiled language specific com binaries from the xswap folder.
I don't know, if there is some sort of infrastructure to swap them automatically or setting tool to change the language.
Very nice, and quite close to the correct value. :) Surprising, considering the rough edges. I wonder, would a bigger circle get you closer to the real value if Pi? I would assume that a larger circle would "lose" less pixels on the border. Can that graphic library switch to 1024x768 or higher? :)
I waited my whole life for this but I don't think it's really related: 4b1b said area inside blocky function can go to the function it's approximating but the circumference stays as if it were the cubic path
For a resolution of 1024x768 pixels you need a VESA capable SVGA mode. VGA goes only to 640x480 at 16 colors.
I don't know if the Watcom graphic library does support VESA modes, but taking the version of the watcom c compiler into account it would make sense.
@@OpenGL4ever My first graphic card ET4000 ISA 1 mb VRAM had 1024x768 and 1280x1024 with 16 color graphic mode in A0000 with bank switching for next 64 kb on port 03CD.
modenumber = 29h ; 16 colors 800 x 600 A000
modenumber = 37h ; 16 colors 1024 x 786 A000
modenume r = 3Dh ; 16 colors 1280 x 1024 A000
@@maxmuster7003 The ET4000 was a SVGA card with VESA modes.
@@OpenGL4ever But the shown numbers are not VBE modenumbers.
just as reference: the area of a circle with a diameter of 480 units is approximately 180956 square units (240*240*3.14159)
Yes, that's correct. This is probably off by a bit because of how the _ellipse function draws a circle. but 3.14 is still pretty good.