Problem with drawing Bezeir curve
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Problem with drawing Bezeir curve

  1. #1
    Join Date
    Jun 1999
    Posts
    490

    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.
    Attached Images Attached Images  
    Last edited by Zulfi Khan2; February 9th, 2014 at 09:09 AM.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,014

    Re: Problem with drawing Bezeir curve

    Quote Originally Posted by Zulfi Khan2 View Post
    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?
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Jun 1999
    Posts
    490

    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. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,471

    Re: Problem with drawing Bezeir curve

    Quote Originally Posted by Zulfi Khan2 View Post
    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.
    Victor Nijegorodov

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,127

    Re: Problem with drawing Bezeir curve

    Quote Originally Posted by Zulfi Khan2 View Post
    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. #6
    Join Date
    Jun 1999
    Posts
    490

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center