Hiruni Nimanthi
Hiruni Nimanthi

Reputation: 65

Fixed Rotation in Computer Graphics

private void fixedRotate(int o,int i,double t,double x,double y)
    {
        translate(o, i, -x, -y);
        rotate(o, i, t);
        translate(o, i, x, y);
    }

private void rotate(int o,int i,double t)
    {
        double x1, y1;
        x1 = x[o, i];
        y1 = y[o, i];

        x[o, i] = x1 * Math.Cos(t) - y1 * Math.Sin(t);
        y[o, i] = x1 * Math.Sin(t) + y1 * Math.Cos(t);
    }

So from the translate() method the point goes to the (0,0) point. And then the rotation is done and the point is translated again. But in the rotate() method x1 and x2 will always be 0. So the x[o,i] y[o,i] both are 0. As I can understand this code should return the point to the same place. But the code is working fine. Please explain. Thanks in advance!

Upvotes: 0

Views: 80

Answers (1)

Hiruni Nimanthi
Hiruni Nimanthi

Reputation: 65

Well I figured it out. x and y in the method fixedRotation()means the center of the polygon. Which means if it's a square, the middle point of the square is translated to the center(0,0) point

Upvotes: 1

Related Questions