From 08a2c1f544dd5feaf74401a58b8b0cf171c181d7 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 9 Nov 2017 15:30:33 +0000 Subject: [PATCH] Vector2.setToPolar implemented. --- v3/src/math/Vector2.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/v3/src/math/Vector2.js b/v3/src/math/Vector2.js index 2976b563c..6cb2213a1 100644 --- a/v3/src/math/Vector2.js +++ b/v3/src/math/Vector2.js @@ -54,6 +54,19 @@ var Vector2 = new Class({ return this; }, + // Sets the `x` and `y` values of this object from a given polar coordinate. + // @param {number} azimuth - The angular coordinate, in radians. + // @param {number} [radius=1] - The radial coordinate (length). + setToPolar: function (azimuth, radius) + { + if (radius == null) { radius = 1; } + + this.x = Math.cos(azimuth) * radius; + this.y = Math.sin(azimuth) * radius; + + return this; + }, + equals: function (v) { return ((this.x === v.x) && (this.y === v.y));