dojox.gfx.arc.arcAsBezier
dojo.require("dojox.gfx.arc");
defined in dojox/gfx/arc.js
calculates an arc as a series of Bezier curves given the last point and a standard set of SVG arc parameters, it returns an array of arrays of parameters to form a series of absolute Bezier curves.
Usage
large = Boolean(large);
sweep = Boolean(sweep);
var xRot = m._degToRad(xRotg),
rx2 = rx * rx, ry2 = ry * ry,
pa = m.multiplyPoint(
m.rotate(-xRot),
{x: (last.x - x) / 2, y: (last.y - y) /|> 2}
),
pax2 = pa.x * pa.x, pay2 = pa.y * pa.y,
c1 = Math.sqrt((rx2 * ry2 - rx2 * pay2 - ry2 * pax2) / (rx2 * pay2 + ry2 * pax2));
if(isNaN(c1)){ c1 = 0; }
var ca = {
x: c1 * rx * pa.y / ry,
y: -c1 * ry * pa.x / rx
};
if(large == sweep){
ca = {x: -ca.x, y: -ca.y};
}
// the center
var c = m.multiplyPoint(
[
m.translate(
(last.x + x) / 2,
(last.y + y) / 2
),
m.rotate(xRot)
],
ca
);
// calculate the elliptic transformation
var elliptic_transform = m.normalize([
m.translate(c.x, c.y),
m.rotate(xRot),
m.scale(rx, ry)
]);
// start, end, and size of our arc
var inversed = m.invert(elliptic_transform),
sp = m.multiplyPoint(inversed, last),
ep = m.multiplyPoint(inversed, x, y),
startAngle = Math.atan2(sp.y, sp.x),
endAngle = Math.atan2(ep.y, ep.x),
theta = startAngle - endAngle; // size of our arc in radians
if(sweep){ theta = -theta; }
if(theta < 0){
theta += twoPI;
}else if(theta > twoPI){
theta -= twoPI;
}
// draw curve chunks
var alpha = pi8, curve = curvePI4, step = sweep ? alpha : -alpha,
result = [];
for(var angle = theta; angle > 0; angle -= pi4){
if(angle < pi48){
alpha = angle / 2;
curve = unitArcAsBezier(alpha);
step = sweep ? alpha : -alpha;
angle = 0; // stop the loop
}
var c1, c2, e,
M = m.normalize([elliptic_transform, m.rotate(startAngle + step)]);
if(sweep){
c1 = m.multiplyPoint(M, curve.c1);
c2 = m.multiplyPoint(M, curve.c2);
e = m.multiplyPoint(M, curve.e );
}else{
c1 = m.multiplyPoint(M, curve.c2);
c2 = m.multiplyPoint(M, curve.c1);
e = m.multiplyPoint(M, curve.s );
}
// draw the curve
result.push([c1.x, c1.y, c2.x, c2.y, e.x, e.y]);
startAngle += 2 * step;
}
return result; // Object
parameter | type | description |
---|
last | Object | a point-like object as a start of the arc |
rx | Number | a horizontal radius for the virtual ellipse |
ry | Number | a vertical radius for the virtual ellipse |
xRotg | Number | a rotation of an x axis of the virtual ellipse in degrees |
large | Boolean | which part of the ellipse will be used (the larger arc if true) |
sweep | Boolean | direction of the arc (CW if true) |
x | Number | the x coordinate of the end point of the arc |
y | Number | the y coordinate of the end point of the arc calculate parameters |