This site requires JavaScript, please enable it in your browser!
Greenfoot back
Drawoon
Drawoon wrote ...

2018/1/27

help needed with sin and cos

Drawoon Drawoon

2018/1/27

#
1
2
3
4
5
double x = 0;
double y = 0;
 
x = 17*Math.sin(Math.acos(15/17));
y = 17*Math.cos(Math.asin(8/17));
why do x and y both become 17.0 instead of 8 and 15? and why do they change to 0.0 and 1.04094977.. when I use
1
2
3
4
5
double x = 0;
double y = 0;
 
x = 17*Math.sin(Math.asin(8/17));
y = 17*Math.cos(Math.acos(15/17));
btw this isn't the final way I'm gonna use it in my code but I need it to go on, so just using 15 and 8 doesn't really work here
Vercility Vercility

2018/1/27

#
Hey. Your fractions 8/17 and 15/17 are locally calculated in an integer so you get (int) 8/17 which is 0, just using double as save variable doesnt make it execute as double calcuation. Use 8.0 15.0 and 17.0 instead
You need to login to post a reply.