MCPcopy
hub / github.com/processing/p5.js / setHeading

Method setHeading

src/math/p5.Vector.js:2024–2040  ·  view source on GitHub ↗

* Rotates a 2D vector to a specific angle without changing its magnitude. * * By convention, the positive x-axis has an angle of 0. Angles increase in * the clockwise direction. * * If the vector was created with * createVector() , `setHeading()` uses

(a)

Source from the content-addressed store, hash-verified

2022 * }
2023 */
2024 setHeading(a) {
2025 if (this.dimensions < 2 || (
2026 this._values instanceof Array && this._values.slice(2).some(v => v !== 0))
2027 ) {
2028 p5._friendlyError(
2029 'p5.Vector.setHeading() only supports 2D vectors (z === 0). ' +
2030 'For 3D or higher-dimensional vectors, use rotate() or another ' +
2031 'appropriate method instead.',
2032 'p5.Vector.setHeading'
2033 );
2034 return this;
2035 }
2036 const m = this.mag();
2037 this.x = m * Math.cos(a);
2038 this.y = m * Math.sin(a);
2039 return this;
2040 }
2041
2042 /**
2043 * Rotates a 2D vector by an angle without changing its magnitude.

Callers 1

p5.Vector.jsFile · 0.80

Calls 3

magMethod · 0.95
sliceMethod · 0.80
_friendlyErrorMethod · 0.45

Tested by

no test coverage detected