|
Post by tsh73 on Sept 29, 2019 21:24:23 GMT
Forgive me if it's all obvious. It was not obvious for me, so I share it as a tip. Suppose we run along circle in polar coordinates. And setting dots as we go. - Polar angle (a) goes from 0 to 2*pi
- Radius (r) is fixed
- Each point would be
x=r*cos(a) y=r*sin(a)
question is, how little step (h) we need for "a"? Obviously, bigger "r" needs smaller "h". If "h" is too big, we'll have gaps in our circle. If "h" is too small, we will waste processing time by setting same point several time. So what is right step? Let's count. Let r be 100 So circle length would be 2*pi*r, about 628 pixels. And to pick each pixel we need to divide whole circle (angle 2*pi) into that amount of angles. That gives us 2*pi 1 --------=---=1/r 2*pi*r r
Surprise! Optimal step is 1/r Run and see for yourself, changing "h" (Then I do printScreen with 1/r, floodFill in Paint makes black circle. If I set h=1/r*1.05, paint goes through - we have gaps in circle!) 'What is the optimal step (no gaps) 'in drawing circle by points in polar coordinates? nomainwin open "test" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down" '#gr "fill white; flush" #gr "home; posxy cx cy" r=100 pi=acs(-1) h=1/r 'optimal is 1/r. Bigger leaves gaps 'notice h 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
|
|