I am trying to create a graphing calculator applet using Java. I am having trouble plotting graphs that contain discontinuities such as holes and asymptotes. Here is the code I have for graphs with asymptotes so far:
for (int i = 1; i < size; i++) {
x1 = round((startX + ((graphdata.get(i - 1)).getX()) * scale));
y1 = round((startY - ((graphdata.get(i - 1)).getY()) * scale));
x2 = round((startX + ((graphdata.get(i)).getX()) * scale));
y2 = round((startY - ((graphdata.get(i)).getY()) * scale));
for (int j = 0; j < VertAsympArray.size(); j++)
{
if(Math.abs((round(graphdata.get(i).getX(),3)) - (VertAsympArray.get(j))) > epsilon && Math.abs((round(graphdata.get(i-1).getX(),3)) - (VertAsympArray.get(j))) > epsilon ){
System.out.println("Drawing points : x1 : " + round(graphdata.get(i-1).getX(),3) + ", y1 :" + round(graphdata.get(i-1).getY(),3) + "; x2 : " + round(graphdata.get(i).getX(),3) + ", y2 : " + round(graphdata.get(i).getY(),3) );
g.drawLine(x1, y1, x2, y2);
}
else
System.out.println("VertAsympArray : " + VertAsympArray.get(j) + "; Function x value : " + round(graphdata.get(i).getX(),3));
}
}
Even though I removed the values that make the function the user inputs undefined, for some reason a straight line is drawn connecting the last lowest point on the graph to the next highest point. Here is how a graph looks like for ((x-1)(x+3))/((x+1)(x-6)) around the x = 6 asymptote:
The straight red line is not any asymptote I drew in, it is showing up as part of the function, which is wrong. How do I get rid of it/is there a better way to graph asymptotes?