October 2014
Beginner
366 pages
8h 29m
English
The following JavaScript code converts an arc specified in center-and-angles format to a form suitable for placing into an SVG <path>:
/*Convert an elliptical arc based around a central pointto an elliptical arc parameterized for SVG.Parameters are:center x coordinatecenter y coordinatex-radius of ellipsey-radius of ellipsebeginning angle of arc in degreesarc extent in degreesx-axis rotation angle in degreesReturn value is an array containing:x-coordinate of beginning of arcy-coordinate of beginning of arcx-radius of ellipsey-radius of ellipsex-axis rotation angle in degreeslarge-arc-flag as defined in SVG specificationsweep-flag as defined in SVG specificationx-coordinate of endpoint of arcy-coordinate of endpoint of arc*/functioncenteredToSVG(cx,cy,rx,ry,theta,delta,phi){varendTheta,phiRad;varx0,y0,x1,y1,largeArc,sweep;/*Convert angles to radians. I need a separate variable for phi asradians, because I must preserve phi in degrees for thereturn value.*/theta=theta*Math.PI/180.0;endTheta=(theta+delta)*Math.PI/180.0;phiRad=phi*Math.PI/180.0;/*Figure out the coordinates of the beginning and ending points*/x0=cx+Math.cos(phiRad)*rx*Math.cos(theta)+Math.sin(-phiRad)*ry*Math.sin(theta);y0=cy+Math.sin(phiRad)*rx*Math.cos(theta)+Math.cos(phiRad)*ry*Math.sin(theta);x1=cx ...
Read now
Unlock full access