So, I am again engaged in ring sectors, which are not my forte. I can use the method .arcon canvas very well, the problem arises because my arc is part of the path.
So for example:
ctx.save();
ctx.arc(centerX, centerY, radius, startAngle, endAngle, true);
ctx.stroke();
ctx.restore();
It works great. But now I need this as part of the path, so I have something like this:
var pointArray = [...];
ctx.save();
ctx.moveTo(pointArray[0].x, pointArray[0].y);
ctx.lineTo(pointArray[1].x, pointArray[1].y);
ctx.arcTo(?, ?, pointArray[2].x pointArray[2].y, radius);
The tangent of the tangent coordinate is driving me crazy. Plus, I have a serious problem:
http://www.dbp-consulting.com/tutorials/canvas/CanvasArcTo.html
It sounds like an arc drawn with arcTo can never cover 180 degrees or more of a circle, and there will be times when my ring sector will be more than 180 degrees.
Thanks for helping improve stackoverflow geometric minds!
UPDATE
, svg canvas inter-polarity , , script, !
annularSector : (startAngle,endAngle,innerRadius,outerRadius) ->
startAngle = degreesToRadians startAngle+180
endAngle = degreesToRadians endAngle+180
p = [
[ @centerX+innerRadius*Math.cos(startAngle), @centerY+innerRadius*Math.sin(startAngle) ]
[ @centerX+outerRadius*Math.cos(startAngle), @centerY+outerRadius*Math.sin(startAngle) ]
[ @centerX+outerRadius*Math.cos(endAngle), @centerY+outerRadius*Math.sin(endAngle) ]
[ @centerX+innerRadius*Math.cos(endAngle), @centerY+innerRadius*Math.sin(endAngle) ]
]
angleDiff = endAngle - startAngle
largeArc = (if (angleDiff % (Math.PI * 2)) > Math.PI then 1 else 0)
if @isSVG
commands = []
commands.push "M" + p[0].join()
commands.push "L" + p[1].join()
commands.push "A" + [ outerRadius, outerRadius ].join() + " 0 " + largeArc + " 1 " + p[2].join()
commands.push "L" + p[3].join()
commands.push "A" + [ innerRadius, innerRadius ].join() + " 0 " + largeArc + " 0 " + p[0].join()
commands.push "z"
return commands.join(" ")
else
@gaugeCTX.moveTo p[0][0], p[0][1]
@gaugeCTX.lineTo p[1][0], p[1][1]
@gaugeCTX.arc @centerX, @centerY, outerRadius, startAngle, endAngle, false
@gaugeCTX.lineTo p[3][0], p[3][1]
@gaugeCTX.arc @centerX, @centerY, innerRadius, startAngle, endAngle, false

@gaugeCTX.moveTo p[0][0], p[0][1]
@gaugeCTX.lineTo p[1][0], p[1][1]
@gaugeCTX.arc @centerX, @centerY, outerRadius, startAngle, endAngle, false
@gaugeCTX.lineTo p[3][0], p[3][1]
@gaugeCTX.arc @centerX, @centerY, innerRadius, endAngle, startAngle, true