本文实例讲述了C++画正弦线的实现代码,分享给大家供大家参考。
主要功能代码如下:
复制代码 代码如下:
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
//画正玄线
#define PI 3.1415926
#define SEGMENT 500
int cxClient,cyClient;
RECT rect;
::GetClientRect(hWnd, &rect);
cxClient = rect.right - rect.left;
cyClient = rect.bottom - rect.top;
POINT pt[SEGMENT];
for (int i=0;i<SEGMENT;i++)
{
pt[i].x = i * cxClient/SEGMENT; //cxClient的长度被分成SEGMENT份
pt[i].y = (int)((cyClient/2)*(1 - sin(2 * PI * i/SEGMENT))); //因为sin(2pi)取反,因为数学坐标Y轴向上,而系统中坐标Y轴向下,+cyClient/2是将坐标原点移到左上角
}
::Polyline(hdc, pt, SEGMENT); //绘图函数
EndPaint(hWnd, &ps);
break;
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
//画正玄线
#define PI 3.1415926
#define SEGMENT 500
int cxClient,cyClient;
RECT rect;
::GetClientRect(hWnd, &rect);
cxClient = rect.right - rect.left;
cyClient = rect.bottom - rect.top;
POINT pt[SEGMENT];
for (int i=0;i<SEGMENT;i++)
{
pt[i].x = i * cxClient/SEGMENT; //cxClient的长度被分成SEGMENT份
pt[i].y = (int)((cyClient/2)*(1 - sin(2 * PI * i/SEGMENT))); //因为sin(2pi)取反,因为数学坐标Y轴向上,而系统中坐标Y轴向下,+cyClient/2是将坐标原点移到左上角
}
::Polyline(hdc, pt, SEGMENT); //绘图函数
EndPaint(hWnd, &ps);
break;
希望本文所述对大家的C++程序设计有所帮助。