And since it is necessary to rotate relative to an arbitrary point, then from x and y the distance of this point from the origin of the coordinates is first taken away, and then added. Here is the code (C ++):
void rotate(int &x, int &y, const double &cosVal, const double &sinVal, const int &cx = 0, const int &cy = 0) { const double _x = x - cx; const double _y = y - cy; x = round( _x * cosVal - _y * sinVal); y = round( _x * sinVal + _y * cosVal); x += cx; y += cy; } But it turns out this (the point relative to which is spinning - the center of the triangle): 
(GIF recorded from the moment when the triangle has already begun to deform and "leave" from its center).
