# 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));
}
}
```

## Answers

Your loop should be set up like this instead:

```for (var i = 0; i < steps; i++) {
xValues[i] = (centerX + radius * Math.cos(2 * Math.PI * i / steps));
yValues[i] = (centerY + radius * Math.sin(2 * Math.PI * i / steps));
}
```
• Start your loop at 0
• Step through the entire 2 * PI range, not just PI.
• You shouldn't have the var xValues = [centerX]; var yValues = [centerY]; -- the center of the circle is not a part of it.

Bresenham's algorithm is way faster. You hear of it in relation to drawing straight lines, but there's a form of the algorithm for circles.

Whether you use that or continue with the trig calculations (which are blazingly fast these days) - you only need to draw 1/8th of the circle. By swapping x,y you can get another 1/8th, and then the negative of x, of y, and of both - swapped and unswapped - gives you points for all the rest of the circle. A speedup of 8x!

Change:

```Math.PI * i / steps
```

to:

```2*Math.PI * i / steps
```

A full circle is 2pi radians, and you are only going to pi radians.

If you already have half a circle, just mirror the points to get the other half make sure you do this in the right order.

more speficically, for the other half you simply replace the "+ sin(...)" with a "- sin(...)"

You need to use a partial function to input the radians into cos and sin; therefore take the values you're getting for a quarter or half of the circle, and reflect them over the center points' axis to get your full circle.

That said JavaScript's sin and cos aren't quite as picky, so you must have halved your radian or something; I'd write it as:

```function circle(radius, steps, centerX, centerY){
var xValues = [centerX];
var yValues = [centerY];
var table="<tr><th>Step</th><th>X</th><th>Y</th></tr>";
var ctx = document.getElementById("canvas").getContext("2d");
ctx.fillStyle = "red"
ctx.beginPath();
for (var i = 0; i <= steps; i++) {
var radian = (2*Math.PI) * (i/steps);
xValues[i+1] = centerX + radius * Math.cos(radian);
yValues[i+1] = centerY + radius * Math.sin(radian);
if(0==i){ctx.moveTo(xValues[i+1],yValues[i+1]);}else{ctx.lineTo(xValues[i+1],yValues[i+1]);}
table += "<tr><td>" + i + "</td><td>" + xValues[i+1] + "</td><td>" + yValues[i+1] + "</td></tr>";
}
ctx.fill();
return table;
}
document.body.innerHTML="<canvas id=\"canvas\" width=\"300\" height=\"300\"></canvas><table id=\"table\"/>";
document.getElementById("table").innerHTML+=circle(150,15,150,150);
```

I assumed that for whatever reason you wanted xValues and yValues to be centerX and centerY. I can't figure out why you'd want that, as they're values passed into the function already.

I was able to solve it on my own by multiplying the number of steps by 2:

```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*2-Math.PI/2));
yValues[i] = (centerY + radius * Math.sin(Math.PI * i / steps*2-Math.PI/2));
}
}
```

### Add timeout to procedure waiting for Internet Explorer

I call this sub in my VBScript, which waits for Internet Explorer to finish loading before moving onto the next line:

### Advantages of Domain object representing only elements of one type over being able to represent several different types of elements

1) As far as I’m aware, each domain object instance ( at BLL layer ) should completely represent an element of the domain ( an employee, book, car etc ).
{"ft_lang_label":"__label__en","ft_lang_prob":0.7233909,"math_prob":0.96272045,"size":3629,"snap":"2019-35-2019-39","text_gpt3_token_len":1023,"char_repetition_ratio":0.16193104,"word_repetition_ratio":0.16333333,"special_character_ratio":0.3155139,"punctuation_ratio":0.16535433,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99611294,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-08-18T02:48:14Z\",\"WARC-Record-ID\":\"<urn:uuid:e947d166-c20d-4687-845c-733c23f4eba0>\",\"Content-Length\":\"25170\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2ef76dbd-47d7-4319-8fe2-db94df33c2df>\",\"WARC-Concurrent-To\":\"<urn:uuid:870df3d5-ef49-4cc4-8eea-2d2ccf9ba027>\",\"WARC-IP-Address\":\"107.180.77.63\",\"WARC-Target-URI\":\"http://www.brokencontrollers.com/faq/155649.shtml\",\"WARC-Payload-Digest\":\"sha1:6MNO45RIKHM2PEV3EVQQJX32OFU5PCQR\",\"WARC-Block-Digest\":\"sha1:ZMFAHZWBUDQEBHIATCEBRRZFRCWVSRBT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-35/CC-MAIN-2019-35_segments_1566027313589.19_warc_CC-MAIN-20190818022816-20190818044816-00389.warc.gz\"}"}