Tag: sin

在java中绘制sin(x)的图形

我目前正在尝试在java中绘制sin(x)的图形。 我的指令要求我只使用drawLine()作为绘制图形的方法。 我似乎无法弄清楚如何正确设置我的y值。 现在我所拥有的是一个while循环,用于逐个像素地绘制线条,但无法设法让y值正确。 这是我到目前为止所拥有的。 public class GraphJComponent extends JComponent { public void paintComponent (Graphics g){ Color axis = new Color(128, 128, 128); g.setColor(axis); int xShift = getWidth() / 50; int xShift2 = getWidth() / 100; int yShift = getHeight() / 10; int yShift2 = getHeight() / 17; g.drawLine(xShift,yShift,xShift,getHeight() – yShift); g.drawLine(xShift, getHeight() / 2, […]