How to draw a line using y = mx +b in java?

前端 未结 3 1219
北恋
北恋 2021-01-29 01:45

So I have a program that solves a system of linear equations, but that is not relevant. So what happens is that my program pass two linear equations in the form of: y = mx +b. I

3条回答
  •  臣服心动
    2021-01-29 02:03

    drawLine draws a line between two points. So all you need to do is get two points from your equation and pass them into drawLine.

    Example:

    x1 = 0
    x2 = 10
    y1 = m*x1 + b
    y2 = m*x2 + b;
    g2d.drawLine(x1, y1, x2, y2);
    

    Of course this will draw a line segment between the two points. So you need to figure out which segment of the line you are interested in actually drawing and pick you x values accordingly.

提交回复
热议问题