//========================================================================================== // arc_pdf.txt // Author: Clif Collins Date: Jan 2010 //========================================================================================== //========================================================================================== // arcToPdf (result = 1 to 4 Quadrants) //========================================================================================== function arcToPdf(arc) { var xstart,xsweep,swp,first,text; sweep = arc.sweep; start = arc.start; if (sweep < 0) { start = start + sweep; sweep = - sweep; } start = (start + 360) % 360; sweep = (sweep + 360) % 360; text = ''; xstart = start; xsweep = sweep; first = true; while (xsweep > 0) { swp = 90; if (swp > xsweep) swp = xsweep; xsweep = xsweep - swp; text += PDF_makeArc(arc.cx,arc.cy,arc.radius,xstart,swp,first); first = false; xstart = xstart + swp; } return text; } //========================================================================================== // PDF_makeArc (0 - 90 Arc Quadrants) 4 - 90 deg Arcs make a Circle //========================================================================================== function PDF_makeArc(cx,cy,radius,start,sweep,first) { var d,text var a1,a2,x1,y1,x2,y2; var p0x,p0y,p1x,p1y,p2x,p2y,p3x,p3y; var d1_x,d1_y,d2_x,d2_y,f,z; z = 0.552284749; // 4 ( sqrt(2) - 1) / 3) f = sweep / 90; // 0 - 90 Scale Factor z = z * f; d = radius * z; a1 = start; a2 = (-(90 - sweep)) + start; a1 = (a1 / 180) * Math.PI; a2 = (a2 / 180) * Math.PI; x1 = radius; y1 = 0; x2 = 0; y2 = radius; d1_x = radius; d1_y = d; d2_x = d; d2_y = radius; p0x = x1 * Math.cos(a1); p0y = x1 * Math.sin(a1); p1x = (d1_x * Math.cos(a1)) - (d1_y * Math.sin(a1)); p1y = (d1_x * Math.sin(a1)) + (d1_y * Math.cos(a1)); p2x = - (y2 * Math.sin(a2)); p2y = y2 * Math.cos(a2); p3x = (d2_x * Math.cos(a2)) - (d2_y * Math.sin(a2)); p3y = (d2_x * Math.sin(a2)) + (d2_y * Math.cos(a2)); p0x = p0x + cx; p0y = p0y + cy; p0x = Math.round(p0x * 100) / 100; p0y = Math.round(p0y * 100) / 100; p1x = p1x + cx; p1y = p1y + cy; p1x = Math.round(p1x * 100) / 100; p1y = Math.round(p1y * 100) / 100; p2x = p2x + cx; p2y = p2y + cy; p2x = Math.round(p2x * 100) / 100; p2y = Math.round(p2y * 100) / 100; p3x = p3x + cx; p3y = p3y + cy; p3x = Math.round(p3x * 100) / 100; p3y = Math.round(p3y * 100) / 100; text = ''; if (first) text += p0x + ' ' + p0y + ' m\n'; text += p1x + ' ' + p1y + ' ' + p3x + ' ' + p3y + ' ' + p2x + ' ' + p2y + ' c\n'; return text; }