I have got experience in iPhone programming but not really in graphics programming.
I decided to make a 2d game and choose Quartz 2D for this purpose (I'm familiar with Open GL, but quartz seems to be easier for a 2d game).
Is there a built-in way to draw a graph of a math formula in Quartz? For beginning it will be only a parabola (y=ax^2+bx+c) but the equation itself will become more complex in the future.
It may be pretty slow if I will draw the parabola using my own algorithm (from separate lines or dots).
Thank you in advance.
You could calculate some discrete samples of the equations you want to render.
Your graph will look smooth or polygonal depending on how many samples you provide.
This blog post describes how to render waveforms for a Mac OS X application.
As the author is using Quartz and you can probably adapt his approach for your problem.
The blog post uses the convenient CGPathAddLines() method to create a path from a point array.
If you'd like to construct your path piece by piece, you could use some of the following methods:
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, ...);
CGPathAddLineToPoint(path, ...);
CGPathAddArc(path, ...);
CGPathCloseSubpath(path);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With