HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Formula for calculating angles between coordinates..

04-18-2007, 11:53 AM#1
Toink
I can't say I suck at math because I am asking you this question, I haven't taken up the more advanced algebra yet. I still don't know what the hell sin, cosine, atan, radians and whatever are..

Anywho, can someone show me a formula on how an angle between two coordinates is calculated?

EDIT: Another problem :( I don't know how to do move XY coordinates to another XY coordinate towards the angle..

It's too hard to elaborate.. It's kinda like polar projection but instead of using a location it uses a coordinate.
04-18-2007, 11:58 AM#2
Rising_Dusk
Collapse JASS:
function AngleBetweenPoints takes location locA, location locB returns real
    return bj_RADTODEG * Atan2(GetLocationY(locB) - GetLocationY(locA), GetLocationX(locB) - GetLocationX(locA))
endfunction
That's straight out of BJ.

Here's the version of the wrapper I use.
Collapse JASS:
//***************************************************************************************************************
//*Returns the angle between two points when you give the (X,Y) coordinates.
//*
function AngleBetweenPointsXY takes real x1, real y1, real x2, real y2 returns real
    return 57.29582 * Atan2(y2 - y1, x2 - x1)
endfunction
04-18-2007, 11:59 AM#3
Toink
Thanks! I'll try and understand this :D

EDIT: Sorry can't rep you, have to spread some first <_<

Anywho, I have another problem >_< check the first post please? :D
04-18-2007, 12:10 PM#4
Rising_Dusk
Collapse JASS:
//***************************************************************************************************************
//*Returns a target X value projected from a given X value, a distance, and an angle.
//*
function ProjectX takes real x, real dist, real angle returns real
    return x + dist * Cos(angle * 0.01745)
endfunction


Collapse JASS:
//***************************************************************************************************************
//*Returns a target Y value projected from a given Y value, a distance, and an angle.
//*
function ProjectY takes real y, real dist, real angle returns real
    return y + dist * Sin(angle * 0.01745)
endfunction
04-18-2007, 12:13 PM#5
Toink
I really feel bad that I can't rep you anymore >_<

Anyways, thank you very much!
04-18-2007, 12:13 PM#6
Rising_Dusk
Quote:
I really feel bad that I can't rep you anymore >_<
I don't.
I'm not here to get rep, I'm here to help people.

These are common knowledge functions anyways.
04-18-2007, 12:16 PM#7
Toink
Well then, I'm pretty glad you're here

Oh, and I haven't heard of these functions before :/
04-18-2007, 12:22 PM#8
Rising_Dusk
Here is where they're all located in some form or another.
04-18-2007, 12:28 PM#9
Toink
Wow I must be blessed or something.. xD

Anyways, thanks again :P The link contains almost everything I need :D