# Drawing lines using angles in Java HELP

• October 8th, 2012, 01:28 PM
Drawing lines using angles in Java HELP
Hi All,

Im making a clock in java and i need help drawing the minutes and hours hand. I have done some maths and came up with the following formula

The formula i am using above is x = a + rCos(t)
y = b + rSin(t)
where (x,y) are the points on the circle i am trying to find and (a,b) is the centre of the circle. t is the angle between the x-axis and the line joining (a,b) and (x,y)

My clock is drawing perfectly, only it is 90degrees clockwise, so 12.00 looks like 15.00.
Ive tried to add/subtract degrees to the formula but its not working.

ive only shown the problematic code above, i can show the rest if needed.

Thanks you very much for looking at this,

• October 8th, 2012, 02:02 PM
KevinWorkman
Re: Drawing lines using angles in Java HELP
I'd suggest throwing together an SSCCE that we can play with. I'm not sure I quite understand all the magic numbers in your code. Also note that the Math class has handy methods for converting between radians and degrees that might clear up some confusion.
• October 8th, 2012, 02:14 PM
Re: Drawing lines using angles in Java HELP
Quote:

Originally Posted by KevinWorkman
I'd suggest throwing together an SSCCE that we can play with. I'm not sure I quite understand all the magic numbers in your code. Also note that the Math class has handy methods for converting between radians and degrees that might clear up some confusion.

Sorry about the confusion. Il try to clear it up here:

The user gives me two int's hr and min, which are the hour and minutes to display on this clock. I then convert each hour into degrees, so if i want to show 6 o'clock, i would do 6 * 30 = 180degrees
Similarly for the minutes, 1 minute = 6 degrees (360degrees / 60 minutes)
So if the user wants to show "30 then the program does the math 30*6 = 180 degrees.
There are two hands: a minute hand and an hour hand which uses these values to show the time.

Then i convert degrees into radians by multiplying by PI/180

Assuming HR, MIN is the user inputted time,

Step 1. Convert into degrees:
30HR degrees (hour), 6MIN degrees (minutes)
30HR * PI/180, 6MIN * PI/180
= HR*PI/6 (hours), MIN * PI/180 (minutes)

Then i substitute this in the formula i described in my above post.

Ps. i am trying to edit this code and learning about using the Math class' RadiansConversion method. Pls bear with me whilst i do that.
• October 8th, 2012, 02:33 PM
KevinWorkman
Re: Drawing lines using angles in Java HELP
Depending on how you're doing it, 6:00 shouldn't be 180 degrees, it's 90 degrees. You're assuming that straight up (12:00) is 0 degrees, but I believe that 0 degrees is heading straight to the right, 90 degrees is going down, 180 is to the left, and 270 is up (12:00). I could be wrong, but it would explain your problem.
• October 8th, 2012, 02:40 PM
Re: Drawing lines using angles in Java HELP
Quote:

Originally Posted by KevinWorkman
Depending on how you're doing it, 6:00 shouldn't be 180 degrees, it's 90 degrees. You're assuming that straight up (12:00) is 0 degrees, but I believe that 0 degrees is heading straight to the right, 90 degrees is going down, 180 is to the left, and 270 is up (12:00). I could be wrong, but it would explain your problem.

Thats one posibility i considered, i tried to add 90degrees to my values but it still doesnt point up
i.e.

But what this does is make 9:00 the new 12:00.
I try 90-h, h-90 etc no matter what values i put in it still does not point up.
• October 8th, 2012, 02:51 PM
KevinWorkman
Re: Drawing lines using angles in Java HELP
Well, you're adding 90 to the hours and minutes and not an angle, which doesn't really make sense to me.
• October 8th, 2012, 02:57 PM