# I need know vertex after rotate

**URL:** https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719
**Category:** Coding Questions
**Created:** [July 15, 2019, 3:47am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719 "2019-07-15T03:47:54Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [July 15, 2019, 3:47am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/1 "2019-07-15T03:47:54Z")

</div>

How to find the coordinates of the already drawn Shape?  
More precisely, I need to know its vertex coordinates in order to work with them later.  
I would just count it from the point of creation, but I rotate it.

Is there an opportunity like that?  
Help if you can.

---

<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: [July 15, 2019, 5:19am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/2 "2019-07-15T05:19:05Z")

</div>

Use `screenX()` and `screenY()`.

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [July 15, 2019, 5:20am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/3 "2019-07-15T05:20:55Z")

</div>

I do not know how to do this.((  
Please tell me.

---

<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: [July 15, 2019, 5:57am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/4 "2019-07-15T05:57:35Z")

</div>

Example:

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

void draw() {
  background(0);
  pushMatrix();
  translate(300, 300);
  noFill();
  stroke(128);
  ellipse(0, 0, 400, 400);
  rotate(map(millis()%7000, 0, 7000, 0, TWO_PI));
  line(0, 0, 200, 0);
  translate(200, 0);
  ellipse(0, 0, 200, 200);
  rotate(map(millis()%13000, 0, 13000, 0, TWO_PI));
  line(0, 0, 100, 0);
  float x = screenX( 100, 0 );
  float y = screenY( 100, 0 );  
  popMatrix();
  stroke(255);
  line(x, 0, x, height);
  line(0, y, width, y);
}

```

---

<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: [July 15, 2019, 7:22am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/5 "2019-07-15T07:22:34Z")

</div>

Or look at modelX modelY and modelZ

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [July 15, 2019, 4:20pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/6 "2019-07-15T16:20:36Z")

</div>

I’m trying to figure out how to work with this data, but I don’t get anything, please help me I’m dull.

> [@TfGuy44](#):
>
> screenX

> [@TfGuy44](#):
>
> map

---

<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: [July 15, 2019, 5:00pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/7 "2019-07-15T17:00:07Z")

</div>

> [@NoName](#):
>
> More precisely, I need to know its vertex coordinates in order to work with them later.

It depends from what you want to do with the vertex coordinates.

- Match vertex coordinates with mouse coordinates: use screenX and screenY. Those only give you the 2D coordinates on the screen surface.

- Match vertex coordinates with other 3D coordinates or use vertex coordinates again: use modelX and modelY and modelZ. Full 3D data with all rotations. See reference.

**Full example**

Full example for `screenX` and `screenY` below - please see the two lines in the code marked with “`!!!!`”.

- We monitor the 2D screen position of the 3D shape throughout and store it in a PVector `screenPos` and use this PVector later in mouseOver() for the check with the mouse (using `dist()`).

Please tell me, if this is okay for you. I can provide a more simple example and an example for modelX and modelY and modelZ.

Chrisir

```auto
import peasy.*;

PeasyCam cam;
ArrayList<SphereClass> list = new ArrayList();  

void setup() {
  size(1300, 900, P3D);

  cam=new PeasyCam(this, 400); 

  // init all spheres 
  SphereClass newSphere;

  newSphere=new SphereClass(23, 23, -230, 
    5, 5, 5);
  list.add(newSphere);

  newSphere=new SphereClass(273, 23, -230, 
    10, 5, 20);
  list.add(newSphere);

  newSphere=new SphereClass(3, 153, 30, 
    3, 3, 3);
  list.add(newSphere);
} // func 

void draw() {
  background(0);
  lights(); 

  // loop over all spheres 
  for (SphereClass sphere : list) { 
    // show it
    sphere.display();
  }

  // HUD
  cam.beginHUD();
  fill(255);
  text("use peasycam, click on speroids", 23, 23);
  cam.endHUD();
} // func 

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

void mousePressed() {
  // loop over all spheres 
  for (SphereClass sphere : list) {
    // select / unselect depending on mouse pos 
    sphere.selectWhenMouseOver();
  }//for
}

// ===========================================================

class SphereClass {

  PVector pos; // 3D vector
  PVector sizeSphere; // 3D vector
  PVector screenPos=new PVector(0, 0); // 2D vector  

  boolean selected=false; 

  // constr (pos and size)
  SphereClass(float x, float y, float z, 
    float w, float h, float d) {
    pos = new PVector(x, y, z); // 3D vector
    sizeSphere = new PVector(w, h, d); // 3D vector
  }// constr

  void display() {
    // draw sphere at pos (x, y, z) coordinate and store 2D screen pos

    pushMatrix();
    translate(pos.x, pos.y, pos.z);
    noStroke(); 
    // we choose the color depending on selected 
    if (selected)
      fill(255, 0, 0); // red 
    else
      fill(0, 0, 255); // blue 
    // draw the sphere
    scale(sizeSphere.x, sizeSphere.y, sizeSphere.z); 
    sphere(11);
    // we monitor the 2D screen pos throughout and store it
    screenPos.set(screenX(0, 0, 0), screenY(0, 0, 0)); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    popMatrix();

    // show the 2D screen pos
    if (keyPressed)
      drawSignX(screenPos);
  }

  void drawSignX( PVector pos ) { 
    // Draw a "X" sign
    // 
    float sizeHalf=60; 
    float x=pos.x;
    float y=pos.y;
    float z=pos.z;  
    stroke(255);
    line(x-sizeHalf, y-sizeHalf, z, x+sizeHalf, y+sizeHalf, z); 
    line(x+sizeHalf, y-sizeHalf, z, x-sizeHalf, y+sizeHalf, z);
  }

  boolean selectWhenMouseOver() {
    // select / unselect

    if (mouseOver()) 
      selected=true;
    else 
    selected=false;

    return selected;
  }

  boolean mouseOver() {
    // makes use of the stored positions of screenX and screenY !!!!!!!!!!!!!!!!!!!!!!!!!!
    return 
      dist(mouseX, mouseY, screenPos.x, screenPos.y) < 50;
  }
  //
}//class
//

```

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [July 15, 2019, 5:05pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/8 "2019-07-15T17:05:38Z")

</div>

I need this for further processing of clicks on the figure and the collision of the figure with other figures.

I need to find exactly the Vertex of figure. To further enter it into other functions.

Sorry, i do not quite understand how Screen X will help me to carry out my idea

---

<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: [July 15, 2019, 5:17pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/9 "2019-07-15T17:17:32Z")

</div>

> [@NoName](#):
>
> I need this for further processing of clicks on the figure

This sounds like you use the mouse here. Use screenX and screenY, see example above.

> and the collision of the figure with other figures

This sounds more like modelX etc.

See reference example : [modelX() / Reference / Processing.org](https://www.processing.org/reference/modelX_.html)

Here,

- x,y,z store the vertex data during rotation.

- x,y,z is later used.

Chrisir

---

<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: [July 15, 2019, 9:58pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/10 "2019-07-15T21:58:18Z")

</div>

Can you post your code?

I assume it’s 3D?

We can help you better when we see your code or a small example sketch of the core idea

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [July 15, 2019, 10:05pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/11 "2019-07-15T22:05:41Z")

</div>

I have quite a tangled code, which, in principle, does not explain, it’s a situation, I’ll draw everything in graphs much better.

because as I suppose the modelX/Y/Z does not quite fit me or is clearly not enough I figured out. I just tried to attach it to the case but they didn’t get anything she didn’t solve my problem.

I apologize if your advice fit And I misunderstood something)

---

<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: [July 15, 2019, 10:14pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/12 "2019-07-15T22:14:36Z")

</div>

I see

Maybe you can just calculate the average of the vertexes (PVector center of the cat)

Let’s say you take this center and use dist() to get a collision?

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [July 15, 2019, 10:47pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/13 "2019-07-15T22:47:09Z")

</div>

I am sorry. I just don’t speak English well and use a translator.

see the first picture as a whole, the concept of what should be: there is the first figure and the second figure + player does not move, the figures fly into it:

 ![sketch1563229505969](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/20ea07c7a4bf3097d01dbcf5e05b8ad5ed400ec9.png)  
a round figure is created with which there are no problems. I can count there just a distance for collisions. Now we will not talk about shape2. we will only look at the first figure

but the first figure initially appears on the sides, then we rotate it and use it to move.  
problems in order to calculate how much its rotate is not I will use formulas for triangles this does not apply to this topic, we will not talk about this either.  
unless we consider the option not to rotate the whole figure, but simply to change the coordinates 1 2 3 4 points.

 ![sketch1563229790967](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0948a24e348689616caa1c230ae36ba739ea627f.png)  
 ![sketch1563230215679](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/85941ec70f63e841f5296d54878a7b8ea520c019.png)

because 1 2 3 4 I need to consider in the future a collision to be pressed and so on. it is very important.

How can I know Vertex1 Vеrtex2 Vertex 3 Vertex 4 I honestly do not understand, but I need it.

---

<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: [July 15, 2019, 11:10pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/14 "2019-07-15T23:10:52Z")

</div>

> [@NoName](#):
>
> How can I know Vertex1 Vеrtex2 Vertex 3 Vertex 4

> **[getVertex() / Reference](https://processing.org/reference/PShape_getVertex_.html)**
>
> The getVertex() method returns a PVector with the coordinates of the vertex point located at the position defined by the index parameter. This method works when shapes are created…

I modified sketch so text was on top of shape:

```auto
PShape s;

void setup() 
  {
  size(500, 500, P3D);
  s = createShape();
  s.beginShape(QUADS);
  s.vertex(0, 0);
  s.vertex(160, 0);
  s.vertex(160, 160);
  s.vertex(0, 160);
  s.endShape(CLOSE);
  
  fill(0);
  textAlign(CENTER);
  textSize(16);
  }

void draw() 
  {
  background(255);
  translate(width/2, height/2);
  shape(s);
  
  for (int i = 0; i < s.getVertexCount(); i++) 
    {
    PVector v = s.getVertex(i);
    text(i, v.x+10, v.y);
    text(v.x, v.x-30, v.y-20); 
    text(v.y, v.x+30, v.y-20); 
    }
  }

```

This may not help you but I learned something new.

🙂

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [July 15, 2019, 11:44pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/15 "2019-07-15T23:44:01Z")

</div>

Thank you very much, I tried everything, and I did it.

 ![Screenshot_20190716-023901](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e4973bdf186f16e513561c7651bb1b20361fe90c.png)

I’m just like getting the vertex coordinates. Thank you so much for this. Tomorrow I will try to implement it in my project.  
I have 2:42 AM so tomorrow I’ll write to you whether I’ve done it or not.

😄

---

<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: [July 15, 2019, 11:52pm UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/16 "2019-07-15T23:52:33Z")

</div>

Something else I tried…

This is rotating shape and updating co-ordinates.  
I had to rotate the PVector of the vertex.

```auto
PShape s;
float theta;

void setup() 
  {
  size(600, 600, P2D);
  s = createShape();
  s.beginShape(QUADS);
  s.vertex(0, 0);
  s.vertex(160, 0);
  s.vertex(160, 160);
  s.vertex(0, 160);
  s.endShape(CLOSE);
  
  fill(0);
  textAlign(CENTER);
  textSize(16);
  }

void draw() 
  {
  background(255);
  translate(width/2, height/2);
// theta += TAU/100;
  for (int i = 0; i < s.getVertexCount(); i++) 
    {
    PVector v = s.getVertex(i);
    v.rotate(TAU/1000);
    s.setVertex(i, v);
    
    text(i, v.x+10, v.y);
    text(v.x, v.x-30, v.y-20);
    text(v.y, v.x+30, v.y-20);
    }
    
    shape(s);
  }

```

🙂

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [July 16, 2019, 12:03am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/17 "2019-07-16T00:03:58Z")

</div>

YES, THIS IS EXACTLY WHAT I NEED!!)  
Today I will not sleep again)  
I’ll go try to understand how it works and somehow apply my project.

UPD1:  
Yes I understand and it’s damn cool. 😱 🥳 🥳

---

<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: [July 16, 2019, 1:15am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/18 "2019-07-16T01:15:33Z")

</div>

Get some sleep!

One more example including modelX() and modelY().  
A keyPressed() will stop\noLoop() and start\loop() rotations.

I have some “global” rotations and some shape rotations.  
You can comment these to see how these behave together or individually.

```auto
PShape s;
float theta;

void setup() 
  {
  size(600, 600, P3D);
  s = createShape();
  s.beginShape(QUADS);
  s.vertex(-100, -50);
  s.vertex(100, -50);
  s.vertex(100, 50);
  s.vertex(-100, 50);
  s.endShape(CLOSE);
  
  fill(255, 0, 0);
  textAlign(CENTER);
  textSize(20);
  }

void draw() 
  { 
  background(0);
  println(frameRate);
  s.setStroke(200);
  s.setStrokeWeight(2);
  theta += TAU/1000; // Comment

  translate(width/2, height/2);
  rotate(theta);
  shape(s);
  for (int i = 0; i < s.getVertexCount(); i++) 
    {
    PVector v = s.getVertex(i);
    v.rotate(TAU/2000); // Comment
    s.setVertex(i, v);
    
    fill(255, 0, 0); 
    text(i, v.x+10, v.y);
    text(v.x, v.x-50, v.y-20);
    text(v.y, v.x+50, v.y-20);
    
    fill(0, 255, 255);
    //text(i, v.x+10, v.y);
    text(modelX(v.x, v.y, 0), v.x-50, v.y-40);
    text(modelY(v.x, v.y, 0), v.x+50, v.y-40);    
    
    }
// shape(s);
  }
  
// ***********************************************************

boolean toggleLoop = false;

public void keyPressed()
  {
  toggleLoop = !toggleLoop;
  if (toggleLoop)
    noLoop();
  else
    loop();
  }

```

Please note that we are just exploring one aspect of this and having some fun with it.  
It may not be exactly what you want but is a part of the journey.  
I like to have fun coding and never worked with getVertex() until today.

🙂

---

<div class="post-metadata">

### Author: ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)
#### Post date: [July 16, 2019, 3:57am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/19 "2019-07-16T03:57:12Z")

</div>

Be sure to read the materials a little later.  
Аgain thank you very much)

---

<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: [July 16, 2019, 11:14am UTC](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719/20 "2019-07-16T11:14:06Z")

</div>

You are very welcome.  
Great tutorials here:  
[https://processing.org/tutorials/](https://processing.org/tutorials/)

glv

[Next page](https://discourse.processing.org/t/i-need-know-vertex-after-rotate/12719.md?page=2)
