It has been pitted for a long time, and the offset should be added.
#include<cmath> #include<cstdio> void change(int* x, int* y, int d){ int x0 = *x, y0 = *y; double sita = double(d) / 180.0f * acos(-1); *x = int(double(x0) * cos(sita) - double(y0) * sin(sita)); *y = int(double(x0) * sin(sita) + double(y0) * cos(sita)); } void CTest3View::OnDraw(CDC* pDC) { CTest3Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CPen pen; pen.CreatePen(PS_SOLID, 3 , RGB( 255 , 0 , 0 )); // Create an implementation pen pDC-> SelectObject(pen); int x0 = 300 , y0 = 300 ; int x1 = 0 , y1 = 0 ; int x2 = 200 , y2 = 0 ; int x3 = 200 , y3 = 200 ; int x4 = 0 , y4 = 200 ; int i = 0 , sita =120; for(i = 0;i < 3;++i){ pDC->MoveTo(x1+x0, y1+y0); pDC->LineTo(x2+x0, y2+y0); pDC->LineTo(x3+x0, y3+y0); pDC->LineTo(x4+x0, y4+y0); pDC->LineTo(x1+x0, y1+y0); change(&x2, &y2, sita); change(&x3, &y3, sita); change(&x4, &y4, sita); } }