programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# drawing a sine function

Greenhorn
Posts: 14
I am working on a program that is supposed to draw the function f(x) = Sin(x). However, the output of the program is a horizontal line. Could somebody give me a tip as to where to look? Thanks a bunch in advance.
Here is the code:
class drawSine extends JPanel
{
double f(double x)
{
return 50*Math.sin((x/100.0)*2*Math.PI);
}
// Draw the function
public void drawFunction()
{
repaint();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
// Draw x axis
g.drawLine(10, 100, 390, 100);
// Draw y axis
g.drawLine(200, 30, 200, 390);
// Draw arrows on x axis
g.drawLine(390, 100, 370, 90);
g.drawLine(390, 100, 370, 110);
// Draw arrows on y axis
g.drawLine(200, 30, 190, 50);
g.drawLine(200, 30, 210, 50);
// Draw x, y
g.drawString("X", 370, 70);
g.drawString("Y", 220, 40);
//draw labels for -2PI, 0 and 2PI
g.drawString("-2\u03c0", 100, 110);
g.drawString("0", 200, 110);
g.drawString("2\u03c0", 300, 110);
// Draw function
Polygon p = new Polygon();
double scaleFactor = 0.01;
for (int x=-100; x <= 100; x++)
{
}
// Draw a polygon line by connecting the points in the polygon
g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
}
}

Donny Frank-Rice
Greenhorn
Posts: 14
Never mind. I messed up with my line adding points.
Thanks anyway.