本文介绍了Java中的正弦和余弦图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经构建了一个GUI,我想在该GUI上显示正弦和余弦图.
绘制图形的代码是:
I have built a GUI on which I want to show sine and cosine graphs.
The code for drawing the graph is :
while(x1 < getWidth()) {
x2 = x1 + 1;
y2 = (int)(340 - ((Math.sin(1.5*i*Math.PI/180) * 80)));
g2.drawLine(x1, y1, x2, y2);
x1 = x2;
y1 = y2;
i++;
}
x1 = 300; // x co-ordinate of interpolated origin
y1 = 340; // y co-ordinate of interpolated origin
while(x1 > 0) {
x2 = x1 - 1;
i = -1;
y2 = (int)(340 - ((Math.sin(1.5*i*Math.PI/180) * 80)));
g2.drawLine(x1, y1, x2, y2);
x1 = x2;
y1 = y2;
i--;
}
1.5(度)是我的x轴上的比例(相对于GUI坐标).和1/80,即0.0125是y轴上的比例(相对于GUI坐标).第一部分(正角度)的代码正常工作.但是我得到的只是第二部分的直线(负角).您能否指出第二部分代码中我出了什么问题?
谢谢.
1.5(degrees) is the scale on my x-axis(relative to the GUI co-ordinates). and 1/80 i.e, 0.0125 is the scale on y-axis(relative to the GUI co-ordinates). The code for first part (positive angles) is working correctly. But all I get is a straight line for the second part(negative angles). Can you please point out where am I getting wrong in my code for second part.
Thank you.
推荐答案
这篇关于Java中的正弦和余弦图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!