I am trying to plot mathematical functions and use the CoreGraphics framework. I am calculating a path by manually calculating the y-coordinate of a user defined mathematical function.
To draw the function I have included a simplified version of the code:
CGContextBeginPath(context);
CGContextMoveToPoint(context, coordinateSystemOriginX, coordinateSystemOriginY);
//Add all points
CGContextAddLineToPoint(context, newPoint.x,newPoint.y);
CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextStrokePath(context); //Connect them
This is working fine but sadly the user might input a discontinous function like
y = 10/x //undefined value for x=0
but the graph is drawn at x=0 and the points are connected. See the image:
How can I evaluate undefined points so I am able to draw the graph correctly? I know there IS a solution as there are many plotting websites that draw the graph correctly.
A tip or any type of help would be greatly appreciated. Your are also free to include some magic piece of code ;) Thanks!
NSArray*undefinedPoints = [self someMagicFunction:(id)mathematicalExpression];
//returns 0 for mathematicalExpression = 10/x and 1 for 10/(x-1)
BTW I am using the ANExpressionParser class to parse the user input. (http://mac.softpedia.com/progDownload/ANExpressionParser-Download-86833.html)