get other 3 corners
in
Programming Questions
•
2 years ago
I have to get the corner coordinates of a rotated shape.
I did something simulair before but there the center of the rectangle was really the center.
Now i use a offset where it rotates around so getting the corners is a bit harder.
I managed to get 1 corner, but i can't manage to get the other 3 (or they get on the same place or the place don't make sense or they rotate in the other direction etc).
(p.s. how is the subjcect called about measuring triangles, it was something like triangology i believe but when i seatch for things like that i en up with art or food...).
- float rectWidth = 10;
- float rectHeight = 26;
- float x = 100;
- float y = 100;
- float xCenterOffset = 0;
- float yCenterOffset = 8;
- float rotation = 0;
- void setup() {
- size(300, 300);
- smooth();
- rectMode(CENTER);
- ellipseMode(CENTER);
- }
- void draw() {
- background(104);
- pushMatrix();
- translate(x, y);
- rotate(rotation);
- // offset must be negative here
- rect(-xCenterOffset, -yCenterOffset, rectWidth, rectHeight);
- // no offset for the ellipse cause the purpose is to show the
- // axis where it rotates around
- ellipse(0, 0, 3, 3);
- popMatrix();
- // right bottom corner
- float rectDiag = sqrt(( (rectWidth/2) - xCenterOffset) * ( (rectWidth/2) - xCenterOffset) + ( (rectHeight/2) - yCenterOffset) * ( (rectHeight/2) - yCenterOffset));
- float rectAngle = atan2( (rectHeight/2) - yCenterOffset, (rectWidth/2) - xCenterOffset);
- float cx1 = x + (rectDiag * cos(rectAngle + rotation));
- float cy1 = y + (rectDiag * sin(rectAngle + rotation));
- ellipse(cx1, cy1, 3, 3);
- // others??
- rotation += (radians(1));
- }
1