Split off from: https://stackoverflow.com/questions/31076846/is-it-possible-to-use-javascript-to-draw-an-svg-that-is-precise-to-1-000-000-000
Using floating point precision, there are rounding errors when calculating the position of points on a circle.
Example:
function pointsOnACircle (whichpoint, numberOfPoints, cx, cy, radius) {
//Returns a point along the outside of a circle, starting at (whichpoint=1) = 0 degrees
eachpoint = whichpoint * 2 * Math.PI /numberOfPoints;
var thiscx = cx + (radius * Math.sin(eachpoint));
var thiscy = cy - (radius * Math.cos(eachpoint));
thisPoint = [ thiscx, thiscy ];
return thisPoint;
}
If the function is run as fourthPointofSix = pointsOnACircle (4, 6, 126, 126, 63);
then the points returned are
0: 71.44039956158039
1: 157.50000000000003
Calculating them with the calculator at http://www.ttmath.org/online_calculator, the numbers should be:
0: 71.440399561580365..
1: 157.5
Similarly, if we run fifthPointofSix = pointsOnACircle (5, 6, 126, 126, 63);
then the points returned are:
0: 71.44039956158034
1: 94.50000000000004
They should be:
0: 71.440399561580365...
1: 94.5
Note: the x of both points 4 and 5 should be the same, but they come back different