Detecting asymptotes and other discontinuities from user functions is pretty difficult.
To solve your first problem, perhaps only draw a line between points if they're both in the viewing area. If your point resolution is good enough, I think this would only affect the vertical lines you're trying to avoid. Maybe you could also detect if the points have opposite signs or have a very large difference between them.
I'd also recommend increasing the point resolution to help smooth things out and lessen the effects of any inaccurate results.
People often assign a fixed number of points along the x-axis, when really it should match the curve of the function. For example, a steep line between (0,0) and (1,10) would only get 2 points, whereas an equal length line between (0,0) and (10,1) would get 11 points. I'd dynamically assign more points if I measure the gradient of the function to be steep in that area (assuming you're not doing this already). This would also improve my first idea as it would remove some false-positives, leaving only a single sharp line between two points which is more obvious as an unwanted asymptote. |