So both errors:
- n2 must be declared
n2 = theta + delta; - Functions E and Ed should use
rX rY , not rX rY .
And that fixes it all. Although the original should obviously have preferred to divide the arcs into parts of equal size, rather than into elements of size pi / 4, and then add the rest. Just find out how many parts he will need, and then divide the range so that many parts of equal size seem to be a much more elegant solution, and since the error increases with increasing, it will also be more accurate.
See: https://jsfiddle.net/Tatarize/4ro0Lm4u/ for the working version.
This is not just in the sense that it does not work anywhere. You can see that depending on phi, he does a lot of different bad things. This is really amazingly good. But, broken and everywhere.
https://jsfiddle.net/Tatarize/dm7yqypb/
The reason is because declaration n2 is incorrect and must read:
n2 = theta + delta;
https://jsfiddle.net/Tatarize/ba903pss/ But, fixing the error in indexing, it obviously does not scale there as it should. It is possible that arcs in the svg standard are scaled so that, of course, there can be a solution, whereas in the corresponding code they seem to be clamped.
https://www.w3.org/TR/SVG/implnote.html#ArcOutOfRangeParameters
"If rx, ry and φ are such that there is no solution (basically, the ellipse is not large enough to reach (x1, y1) to (x2, y2)), then the ellipse scales evenly until there is exactly one solution (until the ellipse won't be big enough).
Testing this, since it really has code that needs to scale it, I changed it to green when this code received a call. And it turns green when it is screwed. So yes, this is the inability to scale for some reason:
https://jsfiddle.net/Tatarize/tptroxho/
This means that something uses rx, not scaled rX, and the functions E and Ed:
var enx = cx + rx * Math.cos(phi) * Math.cos(n) - ry * Math.sin(phi) * Math.sin(n);
These rX links should read rX and rY for rY .
var enx = cx + rx * Math.cos(phi) * Math.cos(n) - ry * Math.sin(phi) * Math.sin(n);
Which finally fixes the last error, QED.
https://jsfiddle.net/Tatarize/4ro0Lm4u/
I got rid of the canvas, moved everything to svg and animated it.
var svgNS = "http://www.w3.org/2000/svg"; var svg = document.getElementById("svg"); var arcgroup = document.getElementById("arcgroup"); var curvegroup = document.getElementById("curvegroup"); function doArc() { while (arcgroup.firstChild) { arcgroup.removeChild(arcgroup.firstChild); } //clear old svg data. --> var d = document.createElementNS(svgNS, "path"); //var path = "M100,200 a25,100 -30 0,1 50,-25" var path = "M" + x + "," + y + "a" + rx + " " + ry + " " + phi + " " + fa + " " + fs + " " + " " + x1 + " " + y1; d.setAttributeNS(null, "d", path); arcgroup.appendChild(d); } function doCurve() { var cps = generateBezierPoints(rx, ry, phi * Math.PI / 180, fa, fs, x, y, x + x1, y + y1); while (curvegroup.firstChild) { curvegroup.removeChild(curvegroup.firstChild); } //clear old svg data. --> var d = document.createElementNS(svgNS, "path"); var limit = 4; var path = "M" + x + "," + y; for (var i = 0; i < limit && i < cps.length; i++) { if (i < limit - 1) { path += "C" + cps[i].cpx1 + " " + cps[i].cpy1 + " " + cps[i].cpx2 + " " + cps[i].cpy2 + " " + cps[i].en2.x + " " + cps[i].en2.y; } else { path += "C" + cps[i].cpx1 + " " + cps[i].cpy1 + " " + cps[i].cpx2 + " " + cps[i].cpy2 + " " + (x + x1) + " " + (y + y1); } } d.setAttributeNS(null, "d", path); d.setAttributeNS(null, "stroke", "#000"); curvegroup.appendChild(d); } setInterval(phiClock, 50); function phiClock() { phi += 1; doCurve(); doArc(); } doCurve(); doArc();