开发者

How to draw graph of mathematic function in objective C?

开发者 https://www.devze.com 2023-03-22 14:27 出处:网络
I want to draw graph of function, example y = sin(x) and y = cos(x). How to draw it with out drawing each point (x, sin(x))?

I want to draw graph of function, example y = sin(x) and y = cos(x). How to draw it with out drawing each point (x, sin(x))? Have any class/method 开发者_StackOverflow中文版in Cocoa can do this?


There is no built-in feature to plot function output in Cocoa. The Core Plot library is the leading numerical plotting toolkit, but it provides only data-driven, not function-driven plots. Rasterizing (converting a function to a discrete plot) is a non-trivial problem. As others have pointed out, you want to look into some form of interpolation and do some research on schemes for deciding which points to plot so that the output looks "correct" to a human observer. Again, not a trivial task. I believe Numerical Recipes is a good place to start.


You could use cubic or quadratic Bezier curves to interpolate your discrete points. Bezier curves are well supported by Quartz2D.

This article goes more into the math of interpolation, it is not OS X not iOS centric, but the math is just cross platform.

0

精彩评论

暂无评论...
验证码 换一张
取 消