I am having trouble getting the angle between two points. I have written this function (which has seemed to work for me in other languages, maybe not, i'm not sure now)
So this function, basically, doesn't work, and I have no idea why. I know that its not working, because when I test it like this:
What I should see is a line, from the center of my screen (which is 1024x768) draw through the mouse, that follows it as I move my mouse around the screen. However what happens is strange, and hard to describe, i would recommend testing it yourself. It is as if some angles work, and others are snap-to fit on 45 degree increments. Please help me figure out how to do this, as I'm working on a school project, and its currently inhibited by this weird issue.
Function AngleBetween:Float(x1, y1, x2, y2) ax = x2-x1; ay = y2-y1 ang# = 0 If ax <> 0 Then ang = ATan((y1-y2) / (x1-x2)) Else If ay > 0 Then ang = 90 Else ang = 270 End If End If If ax < 0 And ay < 0 Then ang = ang + 180 End If If ax < 0 And ay >= 0 Then ang = ang + 180 End If Return ang End Function
So this function, basically, doesn't work, and I have no idea why. I know that its not working, because when I test it like this:
SetLineWidth(5) SetColor(0,0,0) ang# = anglebetween(512, 384, MouseX(), MouseY()) DrawLine(512, 384, 512 + 10000*Cos(ang), 384 + 10000*Sin(ang))
What I should see is a line, from the center of my screen (which is 1024x768) draw through the mouse, that follows it as I move my mouse around the screen. However what happens is strange, and hard to describe, i would recommend testing it yourself. It is as if some angles work, and others are snap-to fit on 45 degree increments. Please help me figure out how to do this, as I'm working on a school project, and its currently inhibited by this weird issue.