rotate point
in
Programming Questions
•
1 year ago
How can i rotate p1 according to the angle that c1 makes by moving it around?
- PVector p1;
- PVector center;
- PVector c1;
- void setup() {
- size(400, 400);
- center = new PVector(width/2, height/2);
- p1 = new PVector(center.x + width/4, center.y - height/8);
- c1 = new PVector(center.x, center.y + height/3);
- }
- void draw() {
- background(255);
- ellipse(center.x, center.y, 5, 5);
- ellipse(p1.x, p1.y, 5, 5);
- ellipse(c1.x, c1.y, 5, 5);
- line(p1.x, p1.y, center.x, center.y);
- line(c1.x, c1.y, center.x, center.y);
- }
- void mouseDragged() {
- float a = atan2(c1.y - mouseY, c1.x - mouseX);
- a = -a;
- // rotate p1 from center according to a
- c1.x = mouseX;
- c1.y = mouseY;
- }
1