My problem is simple. As you might now, tan(45) equals 1. When I use Math.tan(45) though, it outputs 1.6197751905438615.
I don't know if it helps, but this is the code I used:
double angle = Math.tan(45);
Any ideas why it's not working?
My problem is simple. As you might now, tan(45) equals 1. When I use Math.tan(45) though, it outputs 1.6197751905438615.
I don't know if it helps, but this is the code I used:
double angle = Math.tan(45);
Any ideas why it's not working?
The argument to Math.tan
is an angle in radians. (This is mentioned in the Javadoc for that method.) You're giving it an angle in degrees.
To fix this, you can convert the angle from degrees to radians by using Math.toRadians
(which multiplies by π/180):
double angle = Math.tan(Math.toRadians(45));
Note that, due to limitations of precision (both of representation and of calculation), this won't be exactly 1; on my machine it comes out to about 0.9999999999999998889776975.