# Need my triangle to point to my mouse

**URL:** https://discourse.processing.org/t/need-my-triangle-to-point-to-my-mouse/12053
**Category:** Coding Questions
**Created:** [June 14, 2019, 2:54am UTC](https://discourse.processing.org/t/need-my-triangle-to-point-to-my-mouse/12053 "2019-06-14T02:54:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Pan](https://avatars.discourse-cdn.com/v4/letter/p/b5e925/32.png) [@Pan](https://discourse.processing.org/u/Pan)
#### Post date: [June 14, 2019, 2:54am UTC](https://discourse.processing.org/t/need-my-triangle-to-point-to-my-mouse/12053/1 "2019-06-14T02:54:50Z")

</div>

Hi, I’m using the google translator …  
I need the tip of my triangle to point to the coordinates of my mouse, here I leave what I could find out and do about it

```auto
void setup(){
  size(500, 500);
}

void draw(){
  PVector v1 = new PVector(width/2, height/2);
  PVector v2 = new PVector(mouseX, mouseY); 
  float r = PVector.angleBetween(v1, v2);
  background(255);
  pushMatrix();
  translate(width/2, height/2);
  rotate(-degrees(r));
  triangle(0,0,50,100,-50,100);
  popMatrix();
}

```

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [June 14, 2019, 7:49am UTC](https://discourse.processing.org/t/need-my-triangle-to-point-to-my-mouse/12053/2 "2019-06-14T07:49:59Z")

</div>

```auto
void setup(){
  size(500, 500);
}

void draw(){
  background(255);
  pushMatrix();
  translate(width/2, height/2);
  rotate(atan2(height/2-mouseY, width/2-mouseX)-HALF_PI);
  triangle(0,0,50,100,-50,100);
  popMatrix();
}

```

This is a more direct computation of the same angle.

---

<div class="post-metadata">

### Author: ![Pan](https://avatars.discourse-cdn.com/v4/letter/p/b5e925/32.png) [@Pan](https://discourse.processing.org/u/Pan)
#### Post date: [June 14, 2019, 9:34am UTC](https://discourse.processing.org/t/need-my-triangle-to-point-to-my-mouse/12053/3 "2019-06-14T09:34:19Z")

</div>

Wow, it’s works 🙂  
Thanks you!
