Java中的正弦和余弦图 [英] Sine and Cosine graph in Java

查看:219
本文介绍了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.

推荐答案

仅添加阶段即可解决我的问题,自从我使用三角学或"ALL SILVER TEA CUPS"习语以来已经很长时间了.对于正弦波,我添加了PI/2的相位,对于余弦波,我添加了(1.5)* PI的相位.
Just adding phases solved my problem, it has been a long time since I used trigonometry or the"ALL SILVER TEA CUPS" idiom. For sine wave I have added a phase of PI/2 and for cosine wave I have added a phase of (1.5)*PI.


这篇关于Java中的正弦和余弦图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆