Post by tsh73 on Sept 30, 2019 7:59:26 GMT -5
Recently in thread
on polar drawings appeared different approximations of Pi.
Like,
3 (source of original problem was implicitly admitting Pi=3)
- 22/7
- 355/113
So I got an idea - draw a circle in polar, by changing angle from 0 to (approximated) 2*Pi, and see if difference (gap in circle between 2*pi and 0) still visible.
I looked at circle with radius 100 and 600.
Here's what I got (code below)
approximation | decimalValue (as printed by LB) | note | effect on r=100 | effect on r=600 |
Pi=acs(-1) | 3.14159265 | perfect pi | circle closed | circle closed |
3 | 3 | crude, eh? | big gap | big gap |
3.1 | 3.1 | 1st digit after dot | still a gap | still a gap |
pi*99/100 | 3.11017673 | 1% off | still a gap | still a gap |
pi*179/180 | 3.13286601 | 1 degree off | still a gap | still a gap |
3.14 | 3.14 | 2nd digit after dot | no gap | 2 pixel gap |
2*pi-22/7 | 3.14032816 | 22/7 is actually BIGGER so we subtract to see difference | no gap | single(!) pixel gap |
3.141 | 3.141 | 3rd digit after dot | no gap | no gap |
355/113 | 3.14159292 | 6 right digits | no gap | no gap |
Bottom line.
3.14 is not quite enough, 22/7 is better, 3.141 or further makes your circles perfect, and 355/113 gives you 6 right digits.
'What is effect of different Pi approximation
'on drawing circle by points in polar coordinates?
nomainwin
'open "test" for graphics_nsb_nf as #gr 'default 300x300
open "test" for graphics_nsb_fs as #gr 'as big as we get
#gr "trapclose [quit]"
#gr "down"
'#gr "fill white; flush"
#gr "home; posxy cx cy"
'notice cx; " "; cy
'take bigger coord (cx), round by 100
r=100*int(cx/100) 'I got r=600
pi=acs(-1) 'perfect pi, circle closed at r=100 and r=600
' 3.14159265
pi=3 'big gap
'pi=3.1 'still a gap at r=100
'pi=acs(-1)*99/100 '1% off, still a gap at r=100
' 3.11017673, better then 3.1
'pi=acs(-1)*179/180 'single degree missing - still visible at r=100!
' 3.13286601
'pi=3.14 'no gap visible for r=100, a 2 pixel gap at r =600
'pi=22/7 'is actually MORE then pi. So circle is closed
' 3.14285714
'let's see how much we overshoot (by subracting it from 2*pi)
'pi=2*acs(-1)-22/7 'no gap visible for r=100, single(!) pixel gap at r =600
' 3.14032816, better then 3.14
'pi=3.141 'no gap
'pi=355/113 'no gap
' 3.14159292
prompt "pi~=";pi 'I can copy it from there
h=1/r 'optimal is 1/r. Bigger leaves gaps
'notice h
#gr "place ";cx;" ";20
#gr "\r=";r;" pi~=";pi
FOR a=0 TO 2*pi STEP h
x=cx+r*cos(a)
y=cy+r*sin(a)
'#gr "home; goto ";x;" ";y
#gr "set ";x;" ";y
next
#gr "flush"
wait
[quit]
timer 0
close #gr
end