interpolate two angles

Blitz3D Forums/Blitz3D Programming/interpolate two angles

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Bulletproof:
Graphics 640,480,0,2
SetBuffer BackBuffer()

cx# = GraphicsWidth()*0.5
cy# = GraphicsHeight()*0.5

a# = Rnd(0,360)
b# = Rnd(0,360)

Repeat
	
	Cls
	
	If MouseDown(1)
		a# = ATan2(MouseX()-cx,MouseY()-cy)
	ElseIf MouseDown(2)
		b# = ATan2(MouseX()-cx,MouseY()-cy)
	EndIf
	
	x0# = cx+Sin(a)*100
	y0# = cy+Cos(a)*100

	x1# = cx+Sin(b)*100
	y1# = cy+Cos(b)*100

	c# = interpolate_angle(a,b)
	
	x2# = cx+Sin(c)*100
	y2# = cy+Cos(c)*100

	Color 255,255,255
	Line cx,cy,x0,y0
	Line cx,cy,x1,y1
	
	Text cx+Sin(a)*110,cy+Cos(a)*110,"A",True,True
	Text cx+Sin(b)*110,cy+Cos(b)*110,"B",True,True
		
	Color 255,0,0
	Line cx,cy,x2,y2

	Flip

Until KeyHit(1)

Function interpolate_angle#(a#,b#,blend#=0.5)
	ix# = Sin(a)
	iy# = Cos(a)
	jx# = Sin(b)
	jy# = Cos(b)
	Return ATan2(ix-(ix-jx)*blend,iy-(iy-jy)*blend)
End Function