绘制Path
function ellipse2path(cx, cy, rx, ry, degree) { //cx cy:圆心 //rx ry:x y 轴长 //degree:度数,顺时针方向为正 //思路:求出直线与椭圆的交点,然后从一端绘制到另一端 //非数值单位计算,如当宽度像100%则移除 if (isNaN(cx - cy + rx - ry)) return; //逆时针绘制 var radian = (Math.PI * 2 / 360) * degree var x1 = cx + rx * Math.cos(radian) var y1 = cx + rx * Math.sin(radian) //计算机Y轴正向向下 var x2_relative = 2 * rx * Math.cos(radian) var y2_relative = -2 * rx * Math.sin(radian) var path = ‘M‘ + x1 + ‘ ‘ + y1 + ‘a‘ + rx + ‘ ‘ + ry + ‘ ‘ + degree + ‘ 1 1 ‘ + x2_relative + ‘ ‘ + y2_relative + ‘ ‘ + ‘a‘ + rx + ‘ ‘ + ry + ‘ ‘ + degree + ‘ 1 1 ‘ + -1 * x2_relative + ‘ ‘ + -1 * y2_relative + ‘ ‘ + ‘z‘; return path; }