Jump to content
  • Advertisement


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


How to draw a math function ?

This topic is 5906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 this post

Link to post
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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!