(vector)Rotation for A to point towards B [closed]

Assuming, Point A=vector2( 210,400) B=vector2(-120,480)

Is there a short formula to find the angle to rotate A towards B ? (A is currently heading towards the Y-axis)

Currently, using Pythagorean theorem by getting quadrant info for third point (A.x,B.y) or (B.x,A.y). Then acos... Little complicated.

Respecting A if if B.x>A.x then quadrant=1. Assuming C=(A.x,B.y) Rotation=acos(AC/BC)

• Dec 25, 2022 at 18:37
• Are you intereseted in a formula, say for mathematical interest, or are you trying to solve for the actual angle? VectorAngle is the easiest way to get the latter. In your specific case, VectorAngle[vecA, vecB] will do the trick (where vecA={210,400} and vecB={-120,480}. Apply N to get a finite precision value. Dec 25, 2022 at 19:07
• @lericr VectorAngle[vecA, vecB]? Is it a function we can call in lua or python? Dec 25, 2022 at 22:12
• Possible duplicate better-way-to-calculate-angle-between-lines Dec 26, 2022 at 13:07

VectorAngle returns the same value for rotating $$\vec{a}$$ to $$\vec{b}$$ as it does for rotating $$\vec{b}$$ to $$\vec{a}$$. If you want a formula for the signed angle, try this

Clear[angle]
angle[v1_, v2_] := Arg[Complex @@ v2] - Arg[Complex @@ v1]


Example usage:

{a, b} = {{210, 400}, {-120, 480}};

angle[a, b]/Degree // N   (* 41.735716276 *)

angle[b, a]/Degree // N   (* -41.735716276 *)


Alternative- Real-version(2D)

ArcTan[a . b, Det[{a, b}]]/Degree//N (* 41.7357*)
ArcTan[b . a, Det[{b, a}]]/Degree//N (* -41.7357*)


or ArcTan[a . b, Cross[ a]. b ]/Degree