# Rotating a 2d triangle around its center

## Recommended Posts

n3Xus    951
hello, im trying to rotate a triangle around its center. so the triangle has point A, B and C. can someone point me to an equation for the point components so it will rotate?

##### Share on other sites
SiCrane    11839
There are several different definitions for the center of a triangle: circumcenter, centroid, incenter, orthocenter, and so on. You'll need to decide what kind of center you want.

##### Share on other sites
Aardvajk    13205
Assuming each point of the triangle is defined relative to its centre (e.g. (-10,0)(10,10)(-30,20) sort of thing), you can just do the following for each co-ordinate:

void Rotate(float &X,float &Y,float Angle){    float Tx=X,Ty=Y;    X=(Tx*cosf(Angle))-(Ty*sinf(Angle));    Y=(Ty*cosf(Angle))+(Tx*sinf(Angle));}

where A is the angle in radians.

##### Share on other sites
ahayweh    164
^ what he said. Also, you have to add the original components to the resulting transform.

##### Share on other sites
n3Xus    951
ty very mcuh. work like a charm