[]win32下绘制正弦曲线
[求助]win32下绘制正弦曲线
绘制正弦曲线y=sin x,当apt[0].x=0,应该是apt[0].y=0啊,为什么上面代码中计算api[0].y=1而且绘制的曲线正常呢?
------解决方案--------------------
坐标变换啊
windows 窗体默认的坐标为:原点在左上角,y+方向向下
- C/C++ code
#define TWOPI (2*3.14159) ... LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int cxClient, cyClient ; HDC hdc ; int i ; PAINTSTRUCT ps ; POINT apt [NUM] ; switch (message) { case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; MoveToEx (hdc, 0, cyClient / 2, NULL) ; LineTo (hdc, cxClient, cyClient / 2) ; for (i = 0 ; i < NUM ; i++) { [color=#FF0000] apt[i].x = i * cxClient / NUM ; apt[i].y = (int) (cyClient / 2 * (1-sin (TWOPI * i / NUM))) ;[/color] } Polyline (hdc, apt, NUM) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
绘制正弦曲线y=sin x,当apt[0].x=0,应该是apt[0].y=0啊,为什么上面代码中计算api[0].y=1而且绘制的曲线正常呢?
------解决方案--------------------
坐标变换啊
windows 窗体默认的坐标为:原点在左上角,y+方向向下