diff --git a/rings.ts b/rings.ts new file mode 100644 index 0000000..1260b37 --- /dev/null +++ b/rings.ts @@ -0,0 +1,28 @@ +arcForCircle(radius: number, gapSize: number) { + const svgSize = 100 + const translate = svgSize / 2 + + const MAX_RADIANS = 2 * Math.PI + const gap = (gapSize === 0 ? 0.5 : gapSize) * MAX_RADIANS; + + const startOffset = gap / 2 + const availableTheta = MAX_RADIANS - gap + const largeArc = 1 // The full circle always goes around the large path + + const thetaStart = MAX_RADIANS * 0.75 - startOffset; + const thetaEnd = thetaStart - availableTheta + + if (gap < 0.1) + console.log(gap, startOffset, thetaStart, thetaEnd) + + const [x1, y1] = [Math.cos(thetaStart) * radius + translate, -Math.sin(thetaStart) * radius + translate] + const [x2, y2] = [Math.cos(thetaEnd) * radius + translate, -Math.sin(thetaEnd) * radius + translate] + + if (gapSize === 0) + return `M ${x1} ${y1} + A ${radius} ${radius} 0 1 0 ${x2} ${y2} + M ${x2} ${y2} + A ${radius} ${radius} 0 1 0 ${x1} ${y1}` + else + return `M ${x1} ${y1} A ${radius} ${radius} 0 ${largeArc} 1 ${x2} ${y2}` + } \ No newline at end of file