Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // By: Sherol
- // finding the angle between the hands of a clock
- public class Clock{
- public static void main(String []args){
- System.out.println(getangle(9,45));
- }
- public static double getangle(double hour, double min){
- // get angle from 12 -> min
- // 360/60 (degrees/min) = 6
- double mindeg = min*6;
- System.out.println(mindeg);
- //----------------------------
- // get approx hour angle from 12
- // 360 deg/60 min = 6 deg/min
- double hourdeg = 5 * 6 * (hour%12);
- // add offset
- // each hour has (5 min * 6 degrees/min)
- double minratio = min/60;
- System.out.println(minratio);
- hourdeg = hourdeg + (30.0 * minratio);
- System.out.println(hourdeg);
- //----------------------------
- return (mindeg-hourdeg) % 360 ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement