Getting x and y coordinates along a curve

Aim: to get (x,y) coordinates for circles along an arc.

Hi,

I have been trying to plot circles along an arc and get their locations. I wonder if there is some theta stuff that I need to look into…

this is the design that I want to achieve, along with an array that stores their coordinates.

this is the result of the following code:

let r;
let theta;

function setup() {
  createCanvas(710, 400);
  // Initialize all values
  r = height * 0.45;
  theta = 0;
}

function draw() {
  background(255);

  // Translate the origin point to the center of the screen
  translate(width / 2, height / 2);

  // Convert polar to cartesian
  for(var theta = 0; theta<180; theta+=20){
    let x = r * cos(theta);
    let y = r * sin(theta);
    ellipseMode(CENTER);
    noStroke();
    fill(255,0,0);
    ellipse(x, y, 32, 32);
  }

Many thanks.

Angles need to be expressed as radians not degrees

    let x = r * cos(radians(theta));
    let y = r * sin(radians(theta));

1 Like
1 Like