『主選單』 分類佈告 分類精華 休閒聊天 個人郵件 個人設定 重新登入
 『應數系Java程式設計(楊昌彪老師)』一般區佈告 ←回列表  ↑上一篇  ↓下一篇        張貼  回應 ```發信人: SRF (呵....) 看板: math-java 日期: Tue Apr 25 22:54:49 2000 標題: Cos, sin and tan problems information form http://forum2.java.sun.com/forum?14@@.787c0af0 -------------------------------------------------------------------- 03-apr-00 : 12:53 :damaja Whenever I use the function Math.cos(x), Math.sin(x), Math.tan(x) it gives me the answer as a radient and not in degrees. For example if I calculate Math.cos(45) the answer returned is 0.525322 when I need it to be the equivalent answer in degrees which is 0.7071068. I need to be able to do this as I am rotating 3D coordinates and at present the function simply gives me the wrong value. Can anyone help????? 03-apr-00 14:07 xhunterx (#1 of 2) Add New Message Those methods take their parameters in radians, not in degrees (so you'll need to convert 45? to radians before passing the value as an argument). As it turns out the Math class also (as of SDK 1.2) provides utility methods (toDegrees() and toRadians()) for the inter -conversion of radians and degrees - hence your call would look like this: double cos = Math.cos(Math.toRadians(45)); The methods are of course straightforward, so even if you are dealing with an earlier SDK they are quite easily reproduced: static double degreesToRadians(double degrees) { return degrees / 180d * Math.PI; } static double radiansToDegrees(double radians) { return radians * 180d / Math.PI); - Mark -- * Origin: 中山大學 West BBS-西子灣站 * From: 140.117.12.28 [已通過認證] ``` ←回列表  ↑上一篇  ↓下一篇        張貼  回應