double dx, dy ; int x = pt1.x, y ; int nDiffY = pt1.y - pt2.y; int x1 = pt2.x-pt1.x; int y1 = pt2.y-pt1.y; double fAngle = atan2((double)y1, (double)x1); bool bFirst = true; for (x = x; x < 1024; x++) { dx = x * fAngle; dy = sin (dx) ; y = pt1.y - (int)(dy * nDiffY) ;
幅度就是 pt2.y - pt1.y
int x = pt1.x, y ;
int nDiffY = pt1.y - pt2.y;
int x1 = pt2.x-pt1.x;
int y1 = pt2.y-pt1.y;
double fAngle = atan2((double)y1, (double)x1);
bool bFirst = true;
for (x = x; x < 1024; x++)
{
dx = x * fAngle;
dy = sin (dx) ;
y = pt1.y - (int)(dy * nDiffY) ;
if(bFirst)
pDC->MoveTo(x,y);
pDC->LineTo (x, y) ;
x++;
bFirst = false;
}高手能否帮忙改一下?
给你个画sinx的代码
void CxxxDlg::OnPaint()
{ CRect rect;
GetClientRect(&rect);
const int n = 5000; CPaintDC dc(this);
CPen pen(0, 1, RGB(0, 0, 255));
CPen* pOldPen = dc.SelectObject(&pen); int nWidth = rect.Width();
int nHeight = rect.Height();
dc.SetViewportOrg(nWidth / 2,nHeight - 30);
POINT pt[2 * n];
for(int i = -1 * n; i < n; i++)
{
long cx = (i * nWidth / 2 * 32) / n;
long cy = -100 + sin((double)cx / 32) * (-32);
pt[i + n].x = cx;
pt[i + n].y = cy;
}
dc.Polyline(pt,2 *n ); CDialog::OnPaint();
}
y = sin(w * x) * (pt2.y - pt1.y) + pt1.y;