How to find a pixel after translate and rotation?

edited July 2016 in How To...

For example I have a pixel with coordinates (0,0), and I translate it to (mouseX,mouseY), and rotate it to "rotAngle = atan2(mouseY - pmouseY, mouseX - pmouseX)".... So many transformations. How to find an actual coordinates of this pixel?

Answers

  • Use screenX() and screenY().

  • I'll try this, thanx

  • edited July 2016

    The problem is that I use Push/Pop Matrix, and the program thinks that my pixel is in the (0,0) coordinates, but after tranlsate and rotate it is not in the (0,0) coordinates. I want to compare my pixel color with another pixel color on the screen, and can't do this because I can't find the actual position of my pixel. "screenX" gives me the same unwanted result.

  • Answer ✓
    void setup() {
      size(200, 200);
      stroke(255, 0, 0);
    }
    
    void draw() {
      background(0);
      pushMatrix();
      translate(100, 100);
      rotate(radians(mouseX));
      translate(40, 0);
      rotate(-radians(mouseY));
      translate(0, 20);
      float x = screenX(0, 0);
      float y = screenY(0, 0);
      ellipse(0, 0, 20, 20);
      popMatrix();
      line(0, 0, x, y);
    }
    
Sign In or Register to comment.