CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Problem with drawing Bezeir curve

1. Member
Join Date
Jun 1999
Posts
501

## Problem with drawing Bezeir curve

Hi,
I got a code of Bezeir curve at the following link which was in TurboC:

Here is a C quadratic Bézier curve example using the old graphics.h library.

http://electrofriends.com/source-cod...ontrol-points/
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.
Last edited by Zulfi Khan2; February 9th, 2014 at 09:09 AM.

2. ## Re: Problem with drawing Bezeir curve

Originally Posted by Zulfi Khan2
I have attached the output of the program. Its drawing straight line instead of curve. Somebody plz guide me.
What did you think the curve should look like with those control points?

3. Member
Join Date
Jun 1999
Posts
501

## Re: Problem with drawing Bezeir curve

Hi,
Thanks for your response. I actually dont know. But plz provide me the points where it should develop a Bezeir curve and provide me a reason for this linear behavior also.

Zulfi.

I put the tags.

4. ## Re: Problem with drawing Bezeir curve

Originally Posted by Zulfi Khan2
Hi,
Thanks for your response. I actually dont know. But plz provide me the points where it should develop a Bezeir curve and provide me a reason for this linear behavior also.
Well, first have a look at Bézier curve description in Wiki.
Now take a sheet of paper, draw the XY-axes and put all your four points on the paper based on the coordinates you set:
Code:
```	x[0]=10; y[0]=100;
x[1]=110; y[1]=200;
x[2]=210; y[2]=300;
x[3]=310; y[3]=400;```
What do you see? Are these points not on the same line?
So how do you expect the Bézier curve based on these point to look like?

PS:
Have a look at the
Properties:
• The curve begins at P0 and ends at Pn; this is the so-called endpoint interpolation property.
• The curve is a straight line if and only if all the control points are collinear.
• The start (end) of the curve is tangent to the first (last) section of the Bézier polygon.
Last edited by VictorN; February 10th, 2014 at 10:57 AM.

5. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## Re: Problem with drawing Bezeir curve

Originally Posted by Zulfi Khan2
Hi,
Thanks for your response. I actually dont know. But plz provide me the points where it should develop a Bezeir curve and provide me a reason for this linear behavior also.

Zulfi.
Why don't you think about it a bit. Come up with some points that don't form a straight line. Use a pencil and paper if you have to.

6. Member
Join Date
Jun 1999
Posts
501

## Re: Problem with drawing Bezeir curve

Hi,
Thanks for your advice and time. Actually i thought these are control points. Most slides show drawing of bezeir curves using control points. I thought its also using the same logic. Okay i would try with some non-linear points.

Zulfi.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•