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

Threaded View

  1. #1
    Join Date
    Jun 1999
    Posts
    505

    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 10:09 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured