Assuming Vector2 is (x, y) I want to rotate it by center (or any point it's just a translation so I could do this) by any given angle given in radians.
My target language is javascript.
- Implementation of answerMaciej Kozieja– Maciej Kozieja2017-02-08 15:19:46 +00:00Commented Feb 8, 2017 at 15:19
Add a comment |
1 Answer
Rotation can be performed through a linear transformation ... a matrix multiplication.
Given an point p = (x, y) and a rotation angle θ, the resulting point p' = (x', y') is given by:
p' = R(θ)⋅p where R(θ) is the matrix
| cos(θ) -sin(θ)| R(θ) = | | | sin(θ) cos(θ)| The resulting decomposition is given by
x' = x⋅cos(θ) - y⋅sin(θ) y' = x⋅sin(θ) + y⋅cos(θ) Coding this in JavaScript is left as an exercise to the reader.