The Math class is a wrapper class for a set of useful mathematical functions and constants. All of the methods and fields are static, and there is no public constructor.
java.lang
import java.applet.Applet;
import java.awt.*;
public class Trig1 extends Applet {
public void paint (Graphics g) {
double x;
double y;
int X0;
int Y0;
int X1;
int Y1;
int X2;
int Y2;
int C1;
int C2;
int T1;
int T2;
double ScaleX;
double ScaleY;
double Inc;
Y0 = 160;
x = - 5.0;
ScaleX = 50;
ScaleY = 50;
Inc = 1./ScaleX;
X0 = 250;
y = Math.sin (x);
X1 = X0 + (int) Math.round (ScaleX * x);
Y1 = Y0 - (int) Math.round (ScaleY * y);
y = Math.cos (x);
C1 = Y0 - (int) Math.round (ScaleY * y);
y = Math.tan (x);
T1 = Y0 - (int) Math.round (ScaleY * y);
g.setColor (Color.black);
g.drawLine (0, Y0, X0 + X0, Y0);
g.drawLine (X0, 0, X0, Y0 + Y0);
while (x < 5.0) {
X2 = X0 + (int) Math.round (ScaleX * x);
y = Math.tan (x);
T2 = Y0 - (int) Math.round (ScaleY * y);
if (Math.abs (y) < 4.0) {
g.setColor (Color.green);
g.drawLine (X1, T1, X2, T2);
}
y = Math.sin (x);
Y2 = Y0 - (int) Math.round (ScaleY * y);
g.setColor (Color.blue);
g.drawLine (X1, Y1, X2, Y2);
y = Math.cos (x);
C2 = Y0 - (int) Math.round (ScaleY * y);
g.setColor (Color.red);
g.drawLine (X1, C1, X2, C2);
X1 = X2;
Y1 = Y2;
C1 = C2;
T1 = T2;
x += Inc;
}
g.setColor (Color.red);
g.drawString ("y = cos (x)", X0 - 60, Y0 - (int) ScaleY - 10);
g.setColor (Color.blue);
g.drawString ("y = sin (x)", X0 + 10, Y0 + 20);
g.setColor (Color.green);
g.drawString ("y = tan (x)", X0 + 70, Y0 - 2 * ((int) ScaleY));
setBackground (Color.white);
}
}
| Sun Microsystem | Math Class API | Version 1.6.0 |
|---|---|---|
| Sun Microsystem | Math Class API | Version 1.5.0 |
| Sun Microsystem | Math Class API | Version 1.4.2 |
| Sun Microsystem | Math Class API | Version 1.3.1 |