我目前在做作业方面遇到了一些问题.
这是练习:
(Plot the sine and cosine functions) Write a program that plots the sine function in red and the cosine function in blue.
hint: The Unicode for Pi is \u03c0. To display -2Pi, use g.drawString(“-2\u03c0”, x, y). For a trigonometric function like sin(x), x is in radians. Use the following loop to add the points to a polygon p
for (int x = -170; x <= 170; x++) {
p.addPoint(x + 200, 100 - (int)(50 * Math.sin((x / 100.0) * 2 * Math.PI)));
-2Pi is at (100, 100), the center of the axis is at (200, 100), and 2Pi is at (300, 100)
Use the drawPolyline method in the Graphics class to connect the points.
好吧,所以我所拥有的sin函数与练习中的函数略有不同,但是它起作用所以它应该不是问题.另一方面,余弦函数,我无法找到它的代码所以我没有在我的程序中.
我还需要做的是将-Pi和Pi放在他们可敬的地方的图表上.
所以,这是代码.
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.P