MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / rotate

Method rotate

Data-Structures/Vectors/Vector2.js:123–129  ·  view source on GitHub ↗

* Vector rotation (see https://en.wikipedia.org/wiki/Rotation_matrix) * * @param angleInRadians The angle in radians by which to rotate the vector. * @returns The rotated vector.

(angleInRadians)

Source from the content-addressed store, hash-verified

121 * @returns The rotated vector.
122 */
123 rotate(angleInRadians) {
124 const ca = Math.cos(angleInRadians)
125 const sa = Math.sin(angleInRadians)
126 const x = ca * this.x - sa * this.y
127 const y = sa * this.x + ca * this.y
128 return new Vector2(x, y)
129 }
130
131 /**
132 * Measure angle between two vectors

Callers 1

Vector2.test.jsFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected