Ripples 002

I was not able to calculate the extent of arcs 1 - 19 I can calculate the starting and ending intersection points but I can't work out how to convert that to an angle and extent.

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);

const radius = 4.5; // Scale minimum radius (gaps between concentric circles)
const angle = 306.5;
// Global code will be evaluated once.
const turtle = new Turtle();

rippleSmall(0, 11 * - radius,10);  // draw 10 concentric circles at (x,y n circles)

X1 = 0; 
Y1 = 11 * - radius;
X2 = 0;
Y2= -radius;
centeredCircle(0,Y2, radius * 20, 360) 

drawArc(19,342,323.3);  // (radius,starting-angle,extent)  // I have not found a way to calculate the extent
drawArc(18,334,308.45);
drawArc(17,328,296.6);
drawArc(16,323,286.3);
drawArc(15,318.3,277.253);
drawArc(14,314.5,268.82);
drawArc(13,310.5,261.0);
drawArc(12,306.9,253.69);
drawArc(11,303.2,246.49);
drawArc(10,300,239.90);
drawArc(9,296.8,233.5);
drawArc(8,293.6,227.12);
drawArc(7,290.3,220.70);
drawArc(6,287.3,214.60);
drawArc(5,284.9,209.68);
drawArc(4,281.9,203.38);
drawArc(3,278.2,196.38);
drawArc(2,274.4,188.80);
drawArc(1,272.9,185.70);

console.log(angle); // f12 toggles browser console

if(turtle.xcor() > intersectionArray[0]){
    // an attempt to find the extent required to end the large arcs 
  //  centeredCircle(-90,-90, 5, 270) // try to turn on a flag to show when I have reached the intersection 
}

function rippleSmall (x,y,count){
    turtle.penup();
    turtle.goto(x, y);
    for(var n=1; n <= count; n++){
        turtle.pendown();
           centeredCircle(x,y, radius * n, 360);
        turtle.penup();
        turtle.goto(x, (y + (n* -1) * radius));
    }
}


function drawArc(scale, heading, extent){

    // find the intersection point of Large circle 19 with small circle 10
    intersectionArray = intersectTwoCircles(X1, Y1,radius * 10 , X2, Y2 ,radius * scale)
    turtle.penup();
    turtle.goto(intersectionArray[2], intersectionArray[3])  // radius  19
    turtle.pendown();
    turtle.setheading(heading);  //342  set the angle of the 19th larger circle that intersects 
    turtle.circle(radius * scale, -1 * extent);  // draw the 19th large circle
}


// thanks to Reinder for this function
// Draws a circle centered a specific x,y location 
// and returns the turtle to the original angle after it completes the circle.
function centeredCircle(x,y, radius, ext) {
turtle.penup();
turtle.goto(x,y);
turtle.backward(radius);
turtle.left(90);
turtle.pendown(); turtle.circle(radius, ext);
turtle.right(90); turtle.penup(); turtle.forward(radius); turtle.pendown();
}

// thanks to jupdike/IntersectTwoCircles.js
// https://gist.github.com/jupdike/bfe5eb23d1c395d8a0a1a4ddd94882ac
// based on the math here:
// http://math.stackexchange.com/a/1367732

// x1,y1 is the center of the first circle, with radius r1
// x2,y2 is the center of the second ricle, with radius r2
function intersectTwoCircles(x1,y1,r1, x2,y2,r2) {
    
  var centerdx = x1 - x2;
  var centerdy = y1 - y2;
  var R = Math.sqrt(centerdx * centerdx + centerdy * centerdy);
  if (!(Math.abs(r1 - r2) <= R && R <= r1 + r2)) { // no intersection
    return []; // empty list of results
  }
  // intersection(s) should exist

  var R2 = R*R;
  var R4 = R2*R2;
  var a = (r1*r1 - r2*r2) / (2 * R2);
  var r2r2 = (r1*r1 - r2*r2);
  var c = Math.sqrt(2 * (r1*r1 + r2*r2) / R2 - (r2r2 * r2r2) / R4 - 1);

  var fx = (x1+x2) / 2 + a * (x2 - x1);
  var gx = c * (y2 - y1) / 2;
  var ix1 = fx + gx;
  var ix2 = fx - gx;

  var fy = (y1+y2) / 2 + a * (y2 - y1);
  var gy = c * (x1 - x2) / 2;
  var iy1 = fy + gy;
  var iy2 = fy - gy;

  // note if gy == 0 and gx == 0 then the circles are tangent and there is only one solution
  // but that one solution will just be duplicated as the code is currently written
  return [ix1, iy1, ix2, iy2];
}