|
Post by tsh73 on Nov 27, 2021 15:01:26 GMT
Performs as titled. Now will you guess what I need it for? (will post then done ;) )
'polinom interpolation by 3 points nomainwin open "Do some clicking" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down" '#gr "fill white; flush" #gr "home; posxy cx cy"
#gr "when leftButtonDown [again]"
[again] #gr "cls"
baseX(1)=50:baseX(2)=cx:baseX(3)=250 for i = 1 to 3 baseY(i)=cy/2+cy*rnd(0) next
#gr "size 5; color red" for i = 1 to 3 #gr "set ";baseX(i);" ";baseY(i) next
#gr "size 2; color blue" for x=baseX(1) to baseX(3) y=parabInterp(x) #gr "set ";x;" ";y next
#gr "flush" wait
[quit] timer 0 close #gr end
function parabInterp(x) 'uses arrays of base point baseX(), baseY() y=0 for i = 1 to 3 p=1 for j = 1 to 3 if i<>j then p=p*(x-baseX(j))/(baseX(i)-baseX(j)) end if next y=y+baseY(i)*p next parabInterp=y end function
|
|
|
Post by Brandon Parker on Nov 28, 2021 4:42:32 GMT
Did you mean to have it flipped vertically? Just curious, because JB's GraphicBox has 0 at the top and maxHeight at the bottom, so the parabolas will be inverted. Here is an image from the example's output. Here is an image from Desmos. The points were pulled from your program, and the equation for the line was derived using the output from a quadratic function solver that I wrote and the previously mentioned points. Simply replacing #gr "set ";baseX(i);" ";baseY(i) with... #gr "set ";baseX(i);" ";((cy * 2) - baseY(i)) and... #gr "set ";x;" ";y with... #gr "set ";x;" ";((cy * 2) - y) ...will resolve that if you wish. Not really an issue; I was just curious it is was intentional. {:0) Brandon Parker
|
|
|
Post by tsh73 on Nov 28, 2021 7:38:23 GMT
The goal was to have smooth curve through three points It doesn't really care does Y increase up or down (in the goal (Turkey thread) program, it was not Y but radius smoothly changing)
|
|
|
Post by Brandon Parker on Nov 28, 2021 14:09:59 GMT
I figured that...
{:0)
Brandon Parker
|
|