How to draw a math function ?

Started by
2 comments, last by Golub 21 years, 6 months ago
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
Advertisement
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.
Keys to success: Ability, ambition and opportunity.
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
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

This topic is closed to new replies.

Advertisement