Results 1 to 15 of 15
Thread: Finding points around a circle
- 10-11-2012, 03:55 PM #1
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Finding points around a circle
The problem is to create a clock face which displays the correct time when a user enters a time, say 2:45.
Im having problems, firstly remembering my trig and secondly putting it into practice.
For finding the co ordinates around a circle i use r * cos(a) for x and sin*cos(a) for y. With r being the radius and a being the angle.
When putting this into practice, r is obviously the length of my clock hand but what to use for the angle is where i am having issues.
For finding the angle to use for the x and y minute hand i have found these.
x = PI/2 - PI/30*m
y = PI/2 - PI/2*m
With m being the minute. I have tried these out (not using java) to see if they work but the answers i am getting don't seem right.
Could someone explain the maths behind it for me?
- 10-11-2012, 05:10 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: Finding points around a circle
Java works with radians, i.e. 360 degrees == 2*PI radians. So one minute is 2*PI/60 radians. (PI is defined in the Math class).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-11-2012, 05:36 PM #3
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Finding points around a circle
I think i have it now, so for my minute hand my formula will be below. Assuming the time is 15minutes past. I did the calculations and they fit approximately where i think they should. (200,200) is my centre point hence the 200 + and -.
x =200 + 180* cos(2*PI/60*15)
y =200 - 180* sin(2*PI/60*15)
- 10-12-2012, 03:01 PM #4
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Finding points around a circle
I have tried to implement this but for some reason the hand no longer displays on my frame.
I create the hand like this, this is the only section that has changed.
The clock is created hereJava Code:double minuteXCor =200+(80*Math.cos(2*Math.PI/60*minute)); double minuteYCor =200-(80*Math.sin(2*Math.PI/60*minute)); Line2D.Double clockMinuteHand = new Line2D.Double(200,200,minuteXCor,minuteYCor); g2.draw(clockMinuteHand);
Java Code:import java.awt.Insets; import javax.swing.*; public class ClockViewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.pack(); Insets insets = frame.getInsets(); int addedWidth = insets.left + insets.right; int addedHeight = insets.top + insets.bottom; final int HEIGHT = 400 + addedHeight; final int WIDTH = 400 + addedWidth; frame.setSize(WIDTH, HEIGHT); frame.setTitle("Clock"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Clock newClock = new Clock(hour,min); frame.add(newClock); frame.setVisible(true); } }
- 10-12-2012, 05:27 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: Finding points around a circle
The snippet you've shown us doesn't show the problem. If it worked before and now it doesn't, why not go back to your previous implementation and step by step change the code to what you want it to be?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-13-2012, 05:08 PM #6
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Finding points around a circle
I have no idea why it wasn't working, i replaced it with the original numbers and then put minuteXCor and minuteYCor back in and it displayed correctly then. The problem now is the hand isnt displayed correctly. With 15 set for the minutes that hand faces towards about 50 or ten to the hour. I printed the x and y co ordinates that i had calculated and they came out as 200, 100. Not really sure what i am doing wrong
- 10-13-2012, 05:16 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
Re: Finding points around a circle
Are you putting the hand at pixel (200,100) or the pixel that is offset from the center of the clock by (200,100)?
- 10-13-2012, 05:23 PM #8
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Finding points around a circle
The hand is centred at 200,200. The x and y co ordinate that i calculated came out with co ordinates 200, 100. Those are the numbers i get when i print out the double values onto my clock. The offset pixel is not at the point 200,100 though as i have my clock centred to 200,200 and the hand is pointing towards the top left. I can add a screenshot if that helps you understand what i mean.
- 10-13-2012, 06:09 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
Re: Finding points around a circle
If the center of your circle is at (200,200) and the radius is, say, 100, then the 15 minute should have the hand at 300,200. I guess there are a lot of possible math problems going on.
- 10-16-2012, 04:16 PM #10
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Finding points around a circle
I used this formula and it came back with the correct time for 15 minutes past.
When i change the minute to something different the result is almost identical and the hand doesn't move. Is there something wrong with the original formula?Java Code:double minuteXCor =200+(100*Math.cos(2*Math.PI%60*minute)); double minuteYCor =200-(100*Math.sin(2*Math.PI%60*minute));
- 10-16-2012, 09:36 PM #11
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Finding points around a circle
I found out how to fix the minute hand by swapping the sin and cos around using the original formula.
My problem is now the hour hand, i thought it would simply be the same but PI/12 instead of PI/60 . . . .apparently it isnt that simple.
- 10-17-2012, 08:58 AM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: Finding points around a circle
Think of time t measured in minutes; the minute hand is at position 2*PI*t/60 after t minutes and the hour hand is at position 2*PI*t/60/12.
kins regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-17-2012, 03:52 PM #13
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Finding points around a circle
Thanks for the reply again Jos.
I have tried many variations of the formula you gave but have had no luck.
I have tried replacing hour (or t in your example) with the time in hours or in minute equivalent but the result still doesn't match with what i expect. I have also tried switching the cos and sin around but again that doesnt seem to make much difference.Java Code:double hourXCor = 200+(80*Math.cos(2*Math.PI/60/12*hour)); double hourYCor = 200+(80*Math.sin(2*Math.PI/60/12*hour));
- 10-18-2012, 09:22 PM #14
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Finding points around a circle
I now have this but it is not giving me the expected result
Java Code:double hourXCor = 200+(80*Math.sin(2*Math.PI*minute/(60*12))); double hourYCor = 200-(80*Math.cos(2*Math.PI*minute/(60*12)));
- 10-19-2012, 07:34 AM #15
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
[jFreeChart] Converting screen-points to points, which are relative to the axis
By fyaxic in forum AWT / SwingReplies: 1Last Post: 08-11-2011, 10:46 AM -
Calculating points in a circle
By Masochist in forum New To JavaReplies: 5Last Post: 02-14-2011, 06:36 PM -
Finding the closest point in a list of points
By sAntA199 in forum New To JavaReplies: 8Last Post: 12-13-2009, 08:41 AM -
help me in finding the entry points in the source code of java.....
By aks.nitw in forum Advanced JavaReplies: 0Last Post: 11-25-2008, 09:24 AM -
given number of points(cordinates) , find max points lie on the same line ?
By Hayzam in forum New To JavaReplies: 2Last Post: 08-24-2008, 12:30 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks