1

I'd like to programmatically draw a shape like this where there is an underlying spiral and equally spaced objects along it, placed tangent to the spiral as shown in this sketch:

enter image description here

I found an example of how to determine equally spaced points along the spiral here and am now trying to place hemispheres along the spiral. However, I'm not sure how to calculate the angle the shape needs to be rotated.

enter image description here

This is what I have so far (viewable here):

var totalSegments = 235,hw = 320,hh = 240,segments;
var len = 15;
points = [];
function setup(){
  createCanvas(640,480);
  smooth();
  colorMode(HSB,255,100,100);
  stroke(0);
  noFill();
  //println("move cursor vertically");
}
function draw(){
  background(0);
  translate(hw,hh);
  segments = floor(totalSegments);
  points = getTheodorus(segments,len);
  angles = getAngles(segments, len);
  for(var i = 0 ; i < segments ; i++){
    
    let c = color('blue');
    fill(c);
    noStroke();
    
    // draw shape
    if(i % 2){
      // console.log(i, ' ', angles[i]);
      // try rotating around the object's center
      push();
      // translate(points[i].x, points[i].y)
      rotate(PI/angles[i]);
      
      arc(points[i].x, points[i].y, len*3, len*3, 0, 0 + PI); 
      pop();
    }
    
    // draw spiral
    strokeWeight(20);
    stroke(0,0,100,(20+i/segments));
    if(i > 0) line(points[i].x,points[i].y,points[i-1].x,points[i-1].y);
    
  }
}

function getAngles(segment, len){
  let angles = [];
  let radius = 0;
  let angle = 0;
  for(var i =0; i < segments; i++){
    radius = sqrt(i+1);
    angle += asin(1/radius);
    angles[i] = angle;
  }
  return angles;
}

function getTheodorus(segments,len){
  var result = [];
  var radius = 0;
  var angle = 0;
  for(var i = 0 ; i < segments ; i++){
    radius = sqrt(i+1);
    angle += asin(1/radius);
    result[i] = new p5.Vector(cos(angle) * radius*len,sin(angle) * radius*len);
  }
  return result;
}
scientiffic
  • 9,045
  • 18
  • 76
  • 149
  • I find your question unclear. You want to calculate an angle of rotation for each semicircle, such that it will be tangent to the spiral, is that right? Is there a particular point on the perimeter of the semicircle you want to couch the spiral? (e.g. the center of the straight side, or the center of the curved side?) And if you want the point to be on the curves side of the semicircle, do you want the semicircle on the inside curve of the spiral, or the outside? – Beta Oct 24 '20 at 13:28

1 Answers1

2

Note that your drawing shows Archimedean spiral while link refers to Theodorus one.

Archimedean spiral is described by equation in polar coordinates (rho-theta)

r = a + b * Theta

where a is initial angle, b is scale value (describes distance between arms), r is radius.

And angle Theta + Pi/2 describes normal to spiral in point at parameter Theta

If you need an approximation to divide spiral into (almost) equal segments - use Clackson formula (example here)

theta = 2 * Pi * Sqrt(2 * s / b)

for arc length s

MBo
  • 77,366
  • 5
  • 53
  • 86