svg - Arc rendering bug? -
this first question please gentle. i'm not programmer , not knowledgeable these things.
i have been messing around svg , raphael.js , have encountered "problem" rendering of arcs.
to simplify things let's forget raphael , consider code below:
<html> <body> <svg width="600px" height="400px" viewbox="0 0 600 400"> <circle cx="200" cy="200" r="180" style="stroke: red; fill: none;"/> <line x1="200" y1="220" x2="200" y2="180" style="stroke: black"/> <line x1="180" y1="200" x2="220" y2="200" style="stroke: black"/> <path d="m200,200 l20,208 a180,180 0 0,1 378,170 z" style="stroke: blue; fill:none"/> <path d="m200,200 l20,208 a180,180 0 0,0 378,170 z" style="stroke: green; fill:none"/> </svg> </body> </html> assuming circle has been rendered correctly, expected 2 arcs fall right on top of circle, instead appear offset. (don't have enough rep post picture.)
i have tested in chrome 43, firefox 40 , opera 30.they produce same outcome.
have misunderstood how arc spec works? noticed if change "a180,180" "a100,100" not affect result find rather odd.
update
i'm updating question information given incomplete. here's code raphael:
<html> <head> <script type="text/javascript" src="raphael.js"></script> </head> <body> <div id="pie" style="width:600px; height:400px;"></div> <script type="text/javascript"> var colorarr = ["#468966", "#fff0a5", "#ffb03b"]; var sectorangles = [87.513812, 173.038674, 99.447514]; var paper = raphael("pie"); var startangle = 0; var endangle = 90; var piex = 200; var piey = 200; var pieradius = 180; var x1, y1, x2, y2; var arcdir = 1; //clockwise (var = 0; < sectorangles.length; i++) { startangle = endangle; endangle = startangle + sectorangles[i]; var flag = (endangle - startangle) > 180.0; x1 = math.round( piex + pieradius * math.cos(math.pi * startangle / 180.0) ); y1 = math.round( piey + pieradius * math.sin(math.pi * startangle / 180.0) ); x2 = math.round( piex + pieradius * math.cos(math.pi * endangle / 180.0) ); y2 = math.round( piey + pieradius * math.sin(math.pi * endangle / 180.0) ); var d = "m" + piex + "," + piey + " l" + x1 + "," + y1 + " a" + pieradius + "," + pieradius + " 0 " + +flag + "," + arcdir + " " + x2 + "," + y2 + " z"; var arc = paper.path(d); arc.attr("fill", colorarr[i]); arc.attr("stroke-width", 0.1); } paper.circle( piex, piey, pieradius ).attr({ stroke: "red", "stroke-width": 0.2 }); </script> </body> </html>
the red circle centred @ 200,200 , has radius of 180.
for 2 arcs superimposed, endpoints (20,208 , 378,170) need sit on circumference of circle.
to check, lets calculate distance of 2 points centre of circle.
sqrt((20-200)^2 + (208-200)^2) = 180.177 sqrt((378-200)^2 + (170-200)^2) = 180.510 those radius differences enough cause misalignment. if use more accurate coordinates in arcs, better superimposition.
note also, green arc should have "large-arc-flag" set because on 180 degrees.
<svg width="600px" height="400px" viewbox="0 0 600 400"> <circle cx="200" cy="200" r="180" style="stroke: red; fill: none;"/> <line x1="200" y1="220" x2="200" y2="180" style="stroke: black"/> <line x1="180" y1="200" x2="220" y2="200" style="stroke: black"/> <path d="m200,200 l20.178,208 a180,180 0 0,1 377.482,170 z" style="stroke: blue; fill:none"/> <path d="m200,200 l20.178,208 a180,180 0 1,0 377.482,170 z" style="stroke: green; fill:none"/> </svg>
Comments
Post a Comment