Even better graph! Its pretty much as easy to make that function a continuous curve:
F(d)=G*m1*m2/d^2*(1-(r1+r2)^2/d^2)
Try it out! As the radii approach zero, or the larger x gets, the closer the function is to G*m1*m2/d^2
global pixels_per_unit as float
pixels_per_unit=100
sync on
r1 as float
r1=0
r2 as float
r2=0
m1 as float
m1=0
m2 as float
m2=0
G as float
G=0
set display mode 1280,800,32
do
cls
from#=-4
ato#=8
` F1(d)=G*m1*m2/d^2
`F2(d)=M1*M2(1/(r1+r2)^2-1/d^2)
inc r1,(keystate(16)-keystate(30))/100.0
inc r2,(keystate(17)-keystate(31))/100.0
inc m1,(keystate(18)-keystate(32))/100.0
inc m2,(keystate(19)-keystate(33))/100.0
inc G,(keystate(20)-keystate(34))/100.0
text 0,0,"r1="+str$(r1)
text 0,16,"r2="+str$(r2)
text 0,32,"m1="+str$(m1)
text 0,48,"m2="+str$(m2)
text 0,64,"G="+str$(G)
text 0,80,"density1="+str$(m1/(3.14159265*r1*r1))
text 0,96,"density2="+str$(m2/(3.14159265*r2*r2))
for x#=from# to ato# step 0.005
dot x#*pixels_per_unit+screen width()/2,-G*m1*m2/x#^2*pixels_per_unit+screen height()/2
next x#
for x#=from# to ato# step 0.005
dot x#*pixels_per_unit+screen width()/2,-(G*m1*m2/x#^2)*(1-(r1+r2)^2/x#^2)*pixels_per_unit+screen height()/2
next x#
drawGraphPaper(pixels_per_unit,screen width()/2,screen height()/2,4)
sync
loop
end
function minimum(a as float, b as float)
if a<b then exitfunction a
endfunction b
function drawGraphPaper(PPU as integer, midx as integer, midy as integer, subUnits as integer)
if subunits<=0 then subunits=1
if PPU<=0 then ppu=40
subDist as float
subDist=PPU*1.0/subUnits
counter1 as float =
counter1=-PPU
counter2 as float = 0
w=screen width()
h=screen height()
ink rgb(0,0,40)
line 0,h/2,w,h/2
ink rgb(0,40,0)
line w/2,0,w/2,h
while (counter1+midx<w) or (midx-counter1>0)
inc counter1, PPU
counter2=0
while (counter2<PPU)
inc counter2, subDist
ink rgb(150,150,150),0
line midx+counter1+counter2,midy-2,midx+counter1+counter2,midy+2
line midx-counter1+counter2,midy-2,midx-counter1+counter2,midy+2
endwhile
ink rgb(255,255,255),0
line midx+counter1,midy-5,midx+counter1,midy+5
line midx-counter1,midy-5,midx-counter1,midy+5
endwhile
counter1=-PPU
counter2=0
while (counter1+midy<w) or (midy-counter1>0)
inc counter1, PPU
counter2=0
while (counter2<PPU)
inc counter2, subDist
ink rgb(150,150,150),0
line midx-2,midy+counter1+counter2,midx+2,midy+counter1+counter2
line midx-2,midy-counter1-counter2,midx+2,midy-counter1-counter2
endwhile
ink rgb(255,255,255),0
line midx-4,midy+counter1,midx+4,midy+counter1
line midx-4,midy-counter1,midx+4,midy-counter1
endwhile
endfunction
function ln(x as float)
n=16
ret#=3.141593/(2*agm(1,4/(x*2^n)))-n*.6931472
endfunction ret#
`arithmetic-geometric mean
function agm(x as float, y as float)
a#=(x+y)/2
g#=sqrt(x*y)
for n=1 to 10
at#=(a#+g#)/2
gt#=sqrt(a#*g#)
a#=at#
g#=gt#
next n
ret#=(a#+g#)/2
endfunction ret#
[edit]
well neither of those worked at all, and everything goes haywire when I try to implement that collision conservation of momentum stuff.
Is't life, I ask, is't even prudence, to bore thyself and bore thy students?