• Status: Solved
• Priority: Medium
• Security: Public
• Views: 1064

# Drawing sinusoidal wave

Hi all again!! do you have a function which draws a sin wave using the sin method of Math class? Or at least, can you guide me in programming that function by myself?

jstuardo@aclaris.cl
0
skel
1 Solution

Commented:
Try this:

import java.awt.*;
import java.applet.*;

public class Test
extends Applet {

private final double scale = 50;
private double step = 1 / scale;

public Test() {
}

public void drawSin(Graphics g, double x0, double x1) {

g.setColor(Color.red);
int i = 0;
int y0 = getBounds().height >> 1;
for (double f = x0; f < x1; f += step,i++) {
g.drawLine(i, (int)((Math.sin(f)) * scale + y0),
i, (int)((Math.sin(f)) * scale + y0));

}
}

public void paint(Graphics g) {
drawSin(g, -Math.PI, Math.PI);
}
}

Hope this helps.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.