Asked • 04/04/19

Circle coordinates to array in Javascript?

What's the best way to add the coordinates of a circle to an array in JavaScript? So far I've only been able to do a half circle, but I need a formula that returns the whole circle to two different arrays: `xValues` and `yValues`. (I'm trying to get the coordinates so I can animate an object along a path.) **Here's what I have so far:** circle: function(radius, steps, centerX, centerY){  var xValues = [centerX];  var yValues = [centerY];  for (var i = 1; i < steps; i++) {   xValues[i] = (centerX + radius * Math.cos(Math.PI * i / steps-Math.PI/2));   yValues[i] = (centerY + radius * Math.sin(Math.PI * i / steps-Math.PI/2)); } }

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.