Ok, I have been working on a Linear Equation program that will draw a line on my graph. But, I am not sure how to set up the y=mx+b in Java to return the (x1,y1) and (x2, y2) using only the slope and y-intercept.
Can anyone tell me how to set up the linear equation in java.
This is a snip bit of my program. First it checks if the user wants to graph something, then it takes the data from the two fields the user entered, [ This part need help on. Getting it to find (x1,y1) and (x2, y2) ], then it converts the answer to points that will match up with the graph lines, draws the data on the graph etc...
Can anyone tell me how to set up the linear equation in java.
Code:
if (Global.psize == 1)//Check If Line Should Be Graphed
{
Global.slope = x1i2;
Global.yinter = y1i2;
Global.yinter = Global.y1i1;// b=y For First Point On y Axis.
pointx1 = (Global.x1i1 * 20 + (15*21));//Converts Window (x,y) To Graph (x,y)
pointy1 = (Global.y1i1 * -20 + (15*21));//Converts Window (x,y) To Graph (x,y)
pointx2 = (Global.x1i2 * 20 + (15*21));//Converts Window (x,y) To Graph (x,y)
pointy2 = (Global.y1i2 * -20 + (15*21));//Converts Window (x,y) To Graph (x,y)
g.fillOval(pointx1,pointy1,10,10);//Draw point
g.fillOval(pointx2,pointy2,10,10);//Draw point
}
Comment