Sunday, August 2, 2009

How can i draw a curve in C++ using graphics??

i want 2 draw d square function graph...can any 1 tell me how 2 do tht thru graphics???

How can i draw a curve in C++ using graphics??
There is a function in the Windows SDK to draw curves, the following is a copy and paste from Microsoft documentation





//------------------------------------...





The Arc function draws an elliptical arc.





BOOL Arc(


HDC hdc, // handle to device context


int nLeftRect, // x-coord of rectangle's upper-left corner


int nTopRect, // y-coord of rectangle's upper-left corner


int nRightRect, // x-coord of rectangle's lower-right corner


int nBottomRect, // y-coord of rectangle's lower-right corner


int nXStartArc, // x-coord of first radial ending point


int nYStartArc, // y-coord of first radial ending point


int nXEndArc, // x-coord of second radial ending point


int nYEndArc // y-coord of second radial ending point


);


Parameters


hdc


[in] Handle to the device context where drawing takes place.


nLeftRect


[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the bounding rectangle.


Windows 95/98/Me: The sum of nLeftRect plus nRightRect must be less than 32768.





nTopRect


[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the bounding rectangle.


Windows 95/98/Me: The sum of nTopRect plus nBottomRect must be less than 32768.





nRightRect


[in] Specifies the x-coordinate, in logical units, of the lower-right corner of the bounding rectangle.


Windows 95/98/Me: The sum of nLeftRect plus nRightRect must be less than 32768.





nBottomRect


[in] Specifies the y-coordinate, in logical units, of the lower-right corner of the bounding rectangle.


Windows 95/98/Me: The sum of nTopRect plus nBottomRect must be less than 32768.





nXStartArc


[in] Specifies the x-coordinate, in logical units, of the ending point of the radial line defining the starting point of the arc.


nYStartArc


[in] Specifies the y-coordinate, in logical units, of the ending point of the radial line defining the starting point of the arc.


nXEndArc


[in] Specifies the x-coordinate, in logical units, of the ending point of the radial line defining the ending point of the arc.


nYEndArc


[in] Specifies the y-coordinate, in logical units, of the ending point of the radial line defining the ending point of the arc.


Return Values


If the arc is drawn, the return value is nonzero.





If the arc is not drawn, the return value is zero.





Windows NT/2000/XP: To get extended error information, call GetLastError.





Remarks


The points (nLeftRect, nTopRect) and (nRightRect, nBottomRect) specify the bounding rectangle. An ellipse formed by the specified bounding rectangle defines the curve of the arc. The arc extends in the current drawing direction from the point where it intersects the radial from the center of the bounding rectangle to the (nXStartArc, nYStartArc) point. The arc ends where it intersects the radial from the center of the bounding rectangle to the (nXEndArc, nYEndArc) point. If the starting point and ending point are the same, a complete ellipse is drawn.





The arc is drawn using the current pen; it is not filled.





The current position is neither used nor updated by Arc.





Windows 95/98/Me: The drawing direction is always counterclockwise.





Windows NT/2000/XP: Use the GetArcDirection and SetArcDirection functions to get and set the current drawing direction for a device context. The default drawing direction is counterclockwise.





Windows 95/98/Me: The sum of the coordinates of the bounding rectangle cannot exceed 32,767. The sum of nLeftRect and nRightRect or nTopRect and nBottomRect parameters cannot exceed 32,767.





Requirements


Windows NT/2000/XP: Included in Windows NT 3.1 and later.


Windows 95/98/Me: Included in Windows 95 and later.


Header: Declared in Wingdi.h; include Windows.h.


Library: Use Gdi32.lib.





//------------------------------------...





You can also use the "paths" section of the GDI


http://msdn2.microsoft.com/en-us/library...





or you can read all about GDI


http://msdn2.microsoft.com/en-us/library...





Or even use GDI+ or even OpenGL or DirectX





http://msdn2.microsoft.com/en-us/library...
Reply:draw a circle and then erase some of it for the opening on the c and for the pluses you can type them
Reply:You have to either:


Define the draw function in terms of a mathematical function as in y=sin(x) which is a curve.


OR


Define the draw function so that it starts at some coordinate, draws to the next, and the next in a curvy fashion, step by step. You can use a loop or try separate compilation with a program like Visual C++





I don't know what the square function graph is though.. sorry.


Hope this helps.
Reply:Drawing environments are platform specific, and you haven't specified what platform you are on, so no one can help you very much. However, all platforms have a routine like Drawline(x0,y0, x1, y1) that draws a line between the two specified points. If you have a function y=f(x), you can use a for loop to step through x, and evaluate f(x) for the y coordinate.





Connecting points with lines gives the smoothest output, but you might find it easier initially to set x0=x1, and y0=y1, meaning that you just draw a simple point at each x value.
Reply:am looking for the same thing.....if anyone can help please let me know


No comments:

Post a Comment