2D maths help

BlitzMax Forums/BlitzMax Beginners Area/2D maths help

The angle would be ATan2( dx , dy ) where dx is the difference between the particles x position and the point of origins x position, and dy is the same, for the y axis.

It's a bit easier to manage if you use vectors.
Type TVector
	Field xcomponent:Double, ycomponent:Double

	Function createVector:TVector(myx:Double, myy:Double)
		Local myVector:TVector = New TVector
		myVector.xcomponent = myx
		myVector.ycomponent = myy
		Return myVector
	End Function
	
	Method getAngle:Double()
		Return ATan2(ycomponent,xcomponent)
	End Method
	
	Method setAngle(myAngle:Double)
		xcomponent = Cos(myAngle)
		ycomponent = Sin(myAngle)
	End Method

	Method deepClone:TVector()
		Local myVector:TVector = New TVector
		myVector.xcomponent = xcomponent
		myVector.ycomponent = ycomponent
		Return myVector
	End Method

End Type
Then the following line:
Local myVector:TVector = TVector.createVector(-x+pocx,-y+pocy)
will create a vector that points at (pocx , pocy) and if you want it to be a "unit" vector, all you have to do is:
myVector.setAngle(myVector.getAngle())