I need know vertex after rotate

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.

1 Like

Use screenX() and screenY().

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

Example:

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);
}
1 Like

Or look at modelX modelY and modelZ

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

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

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
//
1 Like

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

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 : Reference / Processing.org

Here,

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

  • x,y,z is later used.

Chrisir

1 Like

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

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)

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?

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:


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.


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.

1 Like

I modified sketch so text was on top of shape:

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.

:slight_smile:

2 Likes

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

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.

:smile:

Something else I tried…

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

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);
  }

:slight_smile:

2 Likes

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. :scream: :partying_face: :partying_face:

1 Like

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.

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.

:slight_smile:

2 Likes

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

1 Like

You are very welcome.
Great tutorials here:
https://processing.org/tutorials/

glv