Angle Question...

BlitzPlus Forums/BlitzPlus Programming/Angle Question...

Pineapple(Posted 2006) [#1]
Hiya all, I have a little problem :)

In the code below, I have a small dot that follows the mouse, and when I hit the mouse button, I want the dot to travel from the point of the mouse, to another point on the screen!

But, it's not working! Well, it is (ish), so... the question is, how do I get it working properly? :/



Thanks in advance

Dabz

P.S. If this eventually works, it should go straight in the archives, because it's a right bugger of a problem, especially for someone who got a D in maths! :D

*EDIT*
Just noticed, the dot travels through the two points exactly half way... mmmm

Dabz starts scratching his head!!!!


Pineapple(Posted 2006) [#2]
I found this anyway:-

http://www.blitzbasic.com/codearcs/codearcs.php?code=940

Dabz


Pineapple(Posted 2006) [#3]
Not perfect, but it works:-




I'll sleep better tonight knowing that's sorted! :)

Dabz


Andres(Posted 2006) [#4]
Function Angle(basex, basey, targetx, targety)
	If targety>basey-1 Then
		angle=ACos((targetx-basex)/Sqr((targetx-basex)*(targetx-basex)+(targety-basey)*(targety-basey)))
	Else
		If targetx>basex-1 Then
			angle=270+90-ACos((targetx-basex)/Sqr((targetx-basex)*(targetx-basex)+(targety-basey)*(targety-basey)))
		Else
			angle=360-ACos((targetx-basex)/Sqr((targetx-basex)*(targetx-basex)+(targety-basey)*(targety-basey)))
		EndIf
	EndIf

	If targetx=basex And targety=basey Then Return 0 Else Return angle
End Function

Function Distance#(x1#, y1#, x2#, y2#)
	Return Sqr((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
End Function



Pineapple(Posted 2006) [#5]
Thanks Andres, nice functions them! :)

Dabz