# Getting x and y coordinates along a curve

**URL:** <https://discourse.processing.org/t/getting-x-and-y-coordinates-along-a-curve/35760>\
**Category:** Coding Questions\
**Created:** [March 15, 2022, 9:38am UTC](https://discourse.processing.org/t/getting-x-and-y-coordinates-along-a-curve/35760 "2022-03-15T09:38:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bringmeflowers](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bringmeflowers/32/15848_2.png) [@bringmeflowers](https://discourse.processing.org/u/bringmeflowers)\
**Post date:** [March 15, 2022, 9:38am UTC](https://discourse.processing.org/t/getting-x-and-y-coordinates-along-a-curve/35760/1 "2022-03-15T09:38:07Z")

</div>

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.

 ![Screenshot 2022-03-15 at 09.36.47](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4ff069ad19d8b3536690c33426aeb91eb791e02f.jpeg)

this is the result of the following code:

 ![Screenshot 2022-03-15 at 09.34.46](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d773e0d31dfed27676b71b09037d5650d2ff1c65.png)

```auto
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.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [March 15, 2022, 10:46am UTC](https://discourse.processing.org/t/getting-x-and-y-coordinates-along-a-curve/35760/2 "2022-03-15T10:46:45Z")

</div>

> [@bringmeflowers](#):
>
> ```auto
> let x = r * cos(theta);
> let y = r * sin(theta);
> 
> ```

Angles need to be expressed as radians not degrees

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

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 15, 2022, 10:50am UTC](https://discourse.processing.org/t/getting-x-and-y-coordinates-along-a-curve/35760/3 "2022-03-15T10:50:05Z")

</div>

- [p5js.org/reference/#/p5/angleMode](http://p5js.org/reference/#/p5/angleMode)
