1

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.

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.