Circular arc approximation by cubic Bezier curve: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 6: Line 6:
var A = brd.create('glider', [1,0,c], {name:'A'});
var A = brd.create('glider', [1,0,c], {name:'A'});
var B = brd.create('glider', [0,1,c], {name:'B'});
var B = brd.create('glider', [0,1,c], {name:'B'});
var k = function(M, A, B) {
    var ax = A.X()-M.X(),
        ay = A.Y()-M.Y(),
        bx = B.X()-M.X(),
        by = B.Y()-M.Y(),
        d, r;
    r = M.Dist(A);
    d = Math.sqrt((ax+bx)*(ax+bx) + (ay+by)*(ay+by));
    if (Math.abs(by-ay)>JXG.Math.eps) {
        return (ax+bx)*(r/d-0.5)*8.0/3.0/(by-ay);
    } else {
        return (ay+by)*(r/d-0.5)*8.0/3.0/(ax-bx);
    }
};
var P1 = brd.create('point', [
            function(){ return M.X()+A.X()-k(M,A,B)*(A.Y()-M.Y()); },
            function(){ return M.Y()+A.Y()+k(M,A,B)*(A.X()-M.X()); }
], {});
</jsxgraph>
</jsxgraph>



Revision as of 12:26, 1 July 2012

The underlying JavaScript code