Answer the question
In order to leave comments, you need to log in
How to solve the problem of vector rotation towards given coordinates?
Good day. There is a simple algorithm for finding the angle of rotation of a vector in the direction of given coordinates:
// class Unit
lookTo(x, y) {
return Math.atan2(y - this.position.y, x - this.position.x);
}
ccw(x, y) {
return this.position.x * y - this.position.y * x;
}
Answer the question
In order to leave comments, you need to log in
sin(x^y) = x×y / (|x|·|y|) (1st year of the institute, but easily deduced independently)
cos(x^y) = (xy) / (|x|·| y|) (school)
x, y — vectors in 2D
x^y — angle between vectors
x×y — skew product of vectors
(xy) — scalar product of vectors
|x| is the Euclidean length (modulo, 2-norm) of the vector
Hence x^y = atan2( (xy), x×y ).
Perhaps somewhere I missed the sign and I got not x ^ y, but y ^ x.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question