speed?

Blitz3D Forums/Blitz3D Beginners Area/speed?

I am doing an interpolation along a curve using the parabolic function(s):

y = ax^4+bx^3+cx^2+dx+e

I have figured out how to do it up to the ax^5..., but was wondering how far I would need to go to get a good balance between accuracy and speed...I do this about 21 times a loop and the data is accurately to the pixel represented at the ax^5.....

I don't understand maths this good, but if the formula is within a certain range, you could precalculate it maybe into an array. And as I understood, using ax*ax*ax*ax is faster that ax^4.

A(X*X*X*X) would have the benifit of giving the right answer tho

Precalculating into an array is difficult, seeing as though the curve changes throughout the program....

Thanks for the input, I think I will go with A(X*X*X*X)....

I don't understand any of this - I'd like to see a working example - from all parties.

Tomorrow is fine by me.

This is just an overly complicated way to interpolate. For example, to linearly interpolate you can use the equation y = mx + b. If you can find how the line represents the data sets, then you can set it up so that perhaps for how fast you are going (x) then you can figure out how much drag the car will recieve (y)...Taking the data sets, find m(slope) and b(yintecept) (this part easy in calculater) then plug in your x to the equation and it will return for whatever y is at position x. the equations a(X*X*X*X)+b(X*X*X)+c(X*X)+d(X)+e is just a more complicated version of the linear way, that can include a parabolic curve. In other words, it is more acurate. The more times x is multiplied means more accuracy (a,b,c...e have to be recalculated for each accuracy level...where graphing calculater comes in)

Graphics 800, 600, 0, 2
SetBuffer BackBuffer()
font=LoadFont("Arial",300)
SetFont font
Type bubble
	Field image
	Field x#
	Field y#
	Field s
End Type

For i = 0 To 25
	Cls
	r# = Rand(5,80)
	x# = 0
	y# = 0
	d# = Rnd(0,1)
	
	Color 128*d,0,0
	Oval x, y, r, r
	Color 64*d,0,0
	Oval x+r/4,y+r/4,r/1.5,r/1.5
	Color 128*d,0,0
	Oval x+r/4.2,y+r/4.2,r/1.6,r/1.6
	Color 255*d,255*d,255*d
	Oval x+r*0.2, y+r*0.2, r*0.3,r*0.3
	
	image=CreateImage(r,r)
	GrabImage image, 0, 0
	
	bu.bubble = New bubble
	bu\x=Rand(800-r)
	bu\y=Rand(600-r)
	bu\image=image
	bu\s=r
Next

a#= 0.0000001
b# = 0.0005
c#=0.1
d#=0.001
e#=-0.01

time# = - 1000
p# = 1

ClsColor 255, 0, 0
rg#=1
gg#=0
bg#=0
Repeat

ic=(ic Mod 2) + 1
	Select ic
	Case 1
	rg#=1
	bg#=0
	gg#=0
	Case 2
	rg=1
	gg=1
	bg=1
	End Select
	ClsColor 255*rg,255*gg,255*bg
Cls
If Rand(60) < 20 Then txt$ = "PUKI" Else txt$ = "LARGE!"
Color 250*rg, 250*gg, 250*bg: Text 400, 300, txt$, 1, 1

Color 0, 255, 0
zz = (zz + 5) Mod 100
For i = 0 To 150 Step 25
Oval 400 - i * 4 - zz, 300 - i * 4 - zz, i * 8 + zz * 2, i * 8 + zz * 2, 0
Next

For bu.bubble = Each bubble
yy# = (bu\y+offset)
While yy < 0: yy=yy+600:Wend
yy=yy Mod 800
DrawImage bu\image, bu\x, yy#
bu\y=bu\y-bu\s*0.05
If bu\y < -bu\s Then bu\y = bu\y + 680
Next

time# = time# + 5

Color 255*(1-rg),255*(1-gg),255*(1-bg)
For dx# = -400 To 400

x# = dx + time#
y#  = (a * (x*x*x*x)) + (b * (x*x*x)) + (c * (x*x)) + (d * (x))
px# = dx + 400
py# = y / 200 
If dx = 0 Then offset=py-400
py=py-offset
Rect px-5,py-5,10,10

Next

Flip

Until KeyHit(1)

End