Menu
I understand that:
atan2(vector.y, vector.x)
= the angle between the vector and the X axis.But I wanted to know how to get the angle between two vectors using atan2. So I came across this solution:
Arma 3 Contact is a spin-off expansion about humanity's first encounter with extraterrestrial intelligence on Earth. Its alien visitors and military sci-fi singleplayer campaign arrive together with a new sandbox terrain, factions, weapons, vehicles, outfits, equipment, and more. Inside your Arma 3/@ace/ folder, you’ll find the optionals and addons folders. Copy and paste the relevant.pbo and.bisign files from the optionals folder into the addons folder. Copy and paste the userconfig folder from the optionals folder into root Arma 3 folder. Launch Arma 3 with ACE3. Launch Arma 3 to start the official game launcher.
My question is very simple:
Will the two following formulas produce the same number?
atan2(vector1.y - vector2.y, vector1.x - vector2.x)
atan2(vector2.y - vector1.y, vector2.x - vector1.x)
If not: How do I know what vector comes first in the subtractions?
Thanks
user3150201user315020170344 gold badges1616 silver badges2525 bronze badges
10 Answers
is the angle between the difference vector (connecting vector2 and vector1) and the x-axis,which is problably not what you meant.
The (directed) angle from vector1 to vector2 can be computed as
and you may want to normalize it to the range [0, 2 π):
or to the range (-π, π]:
Martin RMartin R416k6161 gold badges935935 silver badges10241024 bronze badges
The proper way to do it is by find the sine of the angle using the cross product, and the cosine of the angle using the dot product and combine the two with the
Atan2()
function.In
C#
this is See test case above in GeoGebra.
ja72ja7218.9k33 gold badges5151 silver badges106106 bronze badges
I think a better formula was posted here:http://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d
So this formula works in 2 or 3 dimensions.For 2 dimensions this formula simplifies to the one stated above.
Eric68.7k3535 gold badges176176 silver badges288288 bronze badges
KlausKlaus
Nobody pointed out that if you have a single vector, and want to find the angle of the vector from the X axis, you can take advantage of the fact that the argument to atan2() is actually the slope of the line, or (delta Y / delta X). So if you know the slope, you can do the following:
given:
A = angle of the vector/line you wish to determine (from the X axis).
m = signed slope of the vector/line.
then:
A = atan2(m, 1)
Very useful!
sbussbus
If you care about accuracy for small angles, you want to use this:
angle = 2*atan2(|| ||b||a - ||a||b ||, || ||b||a + ||a||b ||)
Where '||' means absolute value, AKA 'length of the vector'. See https://math.stackexchange.com/questions/1143354/numerically-stable-method-for-angle-between-3d-vectors/1782769
However, that has the downside that in two dimensions, it loses the sign of the angle.
Community♦
D0SBootsD0SBoots
You don't have to use atan2 to calculate the angle between two vectors. If you just want the quickest way, you can use
dot(v1, v2)=|v1|*|v2|*cos A
to getuser3502079user3502079
As a complement to the answer of @martin-r one should note that it is possible to use the sum/difference formula for arcus tangens.
- Caveat 1: make sure the angle remains within -pi ... +pi
- Caveat 2: beware when the vectors are getting very similar, you might get extinction in the first argument, leading to numerical inaccuracies
6,03922 gold badges1616 silver badges2525 bronze badges
xb,yb and xa,ya are the coordinates of the two vectors
FrankerZ18.2k77 gold badges3232 silver badges6868 bronze badges
theodore panagostheodore panagos
The formula,
angle(vector.b,vector.a)
, that I sent, give results in the four quadrants and for any coordinates
xa,ya
and xb,yb
.For coordinates
xa=ya=0
and orxb=yb=0
is undefined.The angle can be bigger or smaller than
pi
, and can be positiveor negative.
Jan Sršeň1,06811 gold badge1111 silver badges2626 bronze badges
theodore panagostheodore panagos
Here a little program in Python that uses the angle between vectors to determine if a point is inside or outside a certain polygon
Bruno VermeulenBruno Vermeulen
Not the answer you're looking for? Browse other questions tagged mathvectorgeometry or ask your own question.
Hi, I played ACE2 for Arma 2 a year or two ago and now I've bought OA as well, they are in different folders (steam) but there is a batch windows if I chose 'play combined operations' in the arma 2 OA window.
Everything works fine when starting the game. ACE also works fine, except for the problems im about to describe, with the SIX Updater GUI. The problem I have though is that I can't get ACE specific items like the rangefinder, windmeasurer, static spotting scope, earplugs etc to show up in the scroll menu. I've written my name after ACE_IDENTITY in the userconfigACEclientside.something-file. And i've opened clippy, checked that my user was active and started arma, saved in arma, exit and closed clippy.
What am i doing wrong? Right now im pretty frustraded because I've searched everywhere and i can't seem to find any solution.
If something was screwed up in the installation process, wouldn't ACE have more immediate problems? I can do everything else as long as i don't want to use a ACE-item in the scroll menu. Btw, whats this ACE-menu i hear everyone talking about? Does it have anything to do with my problem or do you guys refer to the menu when you press ESC in game, below controls i think?
Everything works fine when starting the game. ACE also works fine, except for the problems im about to describe, with the SIX Updater GUI. The problem I have though is that I can't get ACE specific items like the rangefinder, windmeasurer, static spotting scope, earplugs etc to show up in the scroll menu. I've written my name after ACE_IDENTITY in the userconfigACEclientside.something-file. And i've opened clippy, checked that my user was active and started arma, saved in arma, exit and closed clippy.
What am i doing wrong? Right now im pretty frustraded because I've searched everywhere and i can't seem to find any solution.
If something was screwed up in the installation process, wouldn't ACE have more immediate problems? I can do everything else as long as i don't want to use a ACE-item in the scroll menu. Btw, whats this ACE-menu i hear everyone talking about? Does it have anything to do with my problem or do you guys refer to the menu when you press ESC in game, below controls i think?