Hi,
I got a code of Bezeir curve at the following link which was in TurboC:
I changed the code to:
Code:
void CBezeircurveView::OnDraw(CDC* pDC)
{
CBezeircurveDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int x[4], y[4];
int i;
x[0]=10; y[0]=100;
x[1]=110; y[1]=200;
x[2]=210; y[2]=300;
x[3]=310; y[3]=400;
bezier (x, y, pDC);
}
void CBezeircurveView::bezier (int x[4], int y[4], CDC* pDC)
{
int i;
double t;
for (t = 0.0; t < 1.0; t += 0.0005)
{
double xt = pow (1-t, 3) * x[0] + 3 * t * pow (1-t, 2) * x[1] +
3 * pow (t, 2) * (1-t) * x[2] + pow (t, 3) * x[3];
double yt = pow (1-t, 3) * y[0] + 3 * t * pow (1-t, 2) * y[1] +
3 * pow (t, 2) * (1-t) * y[2] + pow (t, 3) * y[3];
pDC->SetPixel(CPoint(xt, yt), RGB(0,0,0));
}
for (i=0; i<4; i++)
pDC->SetPixel(CPoint(x[i], y[i]), RGB(120, 120, 120));
return;
}
I have attached the output of the program. Its drawing straight line instead of curve. Somebody plz guide me.
Zulfi.