Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotation matrix with center

How is the center vector calculated in this example or in any example. WolframAlpha: http://www.wolframalpha.com/input/?i=rotate+90+degrees+center+%283%2C0%29

like image 929
Starfighter911 Avatar asked Dec 07 '22 16:12

Starfighter911


2 Answers

Homogenous coordinates:

            [ cos(theta) -sin(theta) 0 ]
Rotate    = [ sin(theta)  cos(theta) 0 ]
            [      0           0     1 ]

            [ 1 0 x ]
Translate = [ 0 1 y ]
            [ 0 0 1 ]

So to perform your transformation, you multiply Translate(x, y) * Rotate(theta) * Translate(-x, -y) and get a transformation matrix.

like image 136
Blender Avatar answered Mar 24 '23 00:03

Blender


Or in one function statment

Vector RotateAbout(Vector node, Vector center, double angle)
{
    return new Vector(
        center.X + (node.X-center.X)*COS(angle) - (node.Y-center.Y)*SIN(angle),
        center.Y + (node.X-center.X)*SIN(angle) + (node.Y-center.Y)*COS(angle)
    };
}
like image 41
John Alexiou Avatar answered Mar 23 '23 23:03

John Alexiou