# How do I measure the angle of a vertex?

**URL:** <https://discourse.processing.org/t/how-do-i-measure-the-angle-of-a-vertex/34511>\
**Category:** Coding Questions\
**Created:** [January 7, 2022, 7:22pm UTC](https://discourse.processing.org/t/how-do-i-measure-the-angle-of-a-vertex/34511 "2022-01-07T19:22:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mario60](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mario60](https://discourse.processing.org/u/mario60)\
**Post date:** [January 7, 2022, 7:22pm UTC](https://discourse.processing.org/t/how-do-i-measure-the-angle-of-a-vertex/34511/1 "2022-01-07T19:22:12Z")

</div>

Let me have three points, and the two lines from one of them, the vertex point, to the others two.  
How do I calculate the angle between the two lines?  
I am trying not to use PVectors.

 ![askAngle](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/dd40cfaf7202086edf4657e8d6696f2149d9527a.jpeg)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 7, 2022, 9:56pm UTC](https://discourse.processing.org/t/how-do-i-measure-the-angle-of-a-vertex/34511/2 "2022-01-07T21:56:55Z")

</div>

use atan2 (remark below)

```auto

//https://discourse.processing.org/t/how-do-i-measure-the-angle-of-a-vertex/34511
//https://processing.org/reference/atan2_.html

void setup() {
  size(999, 999);
}

void draw() {
  background(204);

  checkPoint(100, 100);
  checkPoint(555, 120);

  noLoop();
}

//------------------------------------------------------------------------

void checkPoint(float x1, float y1) {
  // 450,450 is the same for all angles. 
  // x1,y1 is the point we want get the angle from

  ellipse(450, 450, 19, 19);
  ellipse(x1, y1, 19, 19);
  line(x1, y1, 
    450, 450); 

  pushMatrix(); 
  translate(450, 450);

  float angle = atan2(y1-450, x1-450); // use y,x here, see https://processing.org/reference/atan2_.html
  println(degrees(angle));
  rotate(angle);

  rect(-30, -5, 60, 10);
  popMatrix(); 
  //
}

```

* * *

**Remark**

Ah, I just realized, `atan2()` sucks. And maths too.

- atan2 gives you often negative values imho
- processing has it’s 0° degrees to the east (and NOT north)

here is a quick work-around:

```auto
//https://discourse.processing.org/t/how-do-i-measure-the-angle-of-a-vertex/34511
//https://processing.org/reference/atan2_.html

void setup() {
  size(999, 999);
}

void draw() {
  background(204);

  pushMatrix(); 

  translate(width/2, height/2);
  float a = atan2(mouseY-height/2, mouseX-width/2);
  rotate(a);
  rect(-30, -5, 60, 10);

  if (a<0) {
    //a=a-PI;
    a=map(a, -PI, 0, PI, TWO_PI);
  }
  a+=HALF_PI;
  if (a>TWO_PI) {
    a-=TWO_PI;
  } 
  popMatrix();

  text(degrees(a), mouseX+13, mouseY);
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [January 9, 2022, 12:09am UTC](https://discourse.processing.org/t/how-do-i-measure-the-angle-of-a-vertex/34511/3 "2022-01-09T00:09:31Z")

</div>

Hello @mario60,

Try to implement this:  
[https://www.cuemath.com/geometry/angle-between-two-lines/](https://www.cuemath.com/geometry/angle-between-two-lines/)

`:)`

---

<div class="post-metadata">

**Author:** ![mario60](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mario60](https://discourse.processing.org/u/mario60)\
**Post date:** [January 9, 2022, 9:42am UTC](https://discourse.processing.org/t/how-do-i-measure-the-angle-of-a-vertex/34511/4 "2022-01-09T09:42:36Z")

</div>

Yes, nice advise. I’ll let you know. Thanks. Cheers.

---

<div class="post-metadata">

**Author:** ![Quertz](https://avatars.discourse-cdn.com/v4/letter/q/cc9497/32.png) [@Quertz](https://discourse.processing.org/u/Quertz)\
**Post date:** [January 23, 2022, 5:11pm UTC](https://discourse.processing.org/t/how-do-i-measure-the-angle-of-a-vertex/34511/5 "2022-01-23T17:11:47Z")

</div>

Dor Product of normed vectors is cos of angle.
