WeBiker - calc anim points

by PhilQ

JavaScript

function deg2rad(degrees) {
	return degrees * (Math.PI/180);
}
function intersection(x0, y0, r0, x1, y1, r1) {
    var a, dx, dy, d, h, rx, ry;
    var x2, y2;

    /* dx and dy are the vertical and horizontal distances between
     * the circle centers.
     */
    dx = x1 - x0;
    dy = y1 - y0;

    /* Determine the straight-line distance between the centers. */
    // d = Math.sqrt((dy*dy) + (dx*dx));
		d = Math.hypot(dx, dy);

    /* Check for solvability. */
    if (d > (r0 + r1)) {
        /* no solution. circles do not intersect. */
        return false;
    }
    if (d < Math.abs(r0 - r1)) {
        /* no solution. one circle is contained in the other */
        return false;
    }

    /* 'point 2' is the point where the line through the circle
     * intersection points crosses the line between the circle
     * centers.  
     */

    /* Determine the distance from point 0 to point 2. */
    a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;

    /* Determine the coordinates of point 2. */
    x2 = x0 + (dx * a/d);
    y2 = y0 + (dy * a/d);

    /* Determine the distance from point 2 to either of the
     * intersection points.
     */
    h = Math.sqrt((r0*r0) - (a*a));

    /* Now determine the offsets of the intersection points from
     * point 2.
     */
    rx = -dy * (h/d);
    ry = dx * (h/d);

    /* Determine the absolute intersection points. */
    var xi = x2 + rx;
    var xi_prime = x2 - rx;
    var yi = y2 + ry;
    var yi_prime = y2 - ry;

    return [xi, xi_prime, yi, yi_prime];
}

/*
var tmp = intersection(
	368, 216.457, 142,
	290.694, 419.569, 134
);
console.log( tmp[0], tmp[2] );
*/

var l_upper = 142, l_lower = 134;
var A = [374, 219.457],
	CC = [290.695,461.0845-20],
	C_r = 41.515 * (3/5),
	A1 = [368,216.457],
	A2 = [378,226.457],
	B = [],
	C = [];

var steps = 16;

for (var i = 0; i <= steps; i++) {
	var deg = (i/steps) * 360;
	var rad = deg2rad( (i/steps) * 360 );
	
	// Calc bottom C
	C[ i ] = [];
	C[ i ][0] = CC[0] + Math.sin(rad)...