• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# How to draw a math function ?

## Recommended Posts

Hi everybody, Maybe the question sound simple but the implementation is more difficult. I want to know how to draw a math function like sine or any general math function without discuntinuity. I use visual c++ or borland c++, and I have no idea how I can draw a single line. Maybe I don''t have the good software ? Any suggestion on best software ? Where I can find source code for this subject ? Where I can find book, article, link... ? Is it possible to use openGL to draw a function in C ? Any help will be appreciated thank''s David Langevin

##### Share on other sites
What are you using to draw to the screen? The GDI, i.e. the standard Windows API? If so then Lines and Curves will get you started.

##### Share on other sites
You do it like you (should have ) learned in school: for every x you compute the y.

So you need a way of plotting pixels (GDI, DirectX, OpenGL etc.), then you just use a loop that looks like

  for ( int x = 0; x < 100; x++ ){     float y = 10 * sin (x);     SetPixel ( x, y );}

that''s the basic way how to do it.

hope that helps

Runicsoft -- home of my open source Function Parser and more

##### Share on other sites
Yepp, calculating the dependent (y) is the one and only way.
I already used that back in good-old ;-> BASIC-times.
And I found out: Better use a "line" from x-value to the next, because you will need many pixel-drawing-steps for curves as tan(x) or x³! Just take the old x/y-pair as start for the next line!

Happy End, dawei

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627680
• Total Posts
2978609

• 13
• 12
• 10
• 12
• 22