-
Jul 26th, 2013, 03:26 PM
#1
Thread Starter
New Member
Shortest distance on a circle formula required
Hi
I am trying to program a dome to sync to a telescope. I need a formula on vb2010 to tell me which is the shortest distance on a circle.
What I Mean is : if point A is at 90 degrees on the circle and point B is at 280 degress which way is way A Move to get to B (clockwise or anti-clockwises)
I hope I have explained my self clearly.
Thank you
-
Jul 26th, 2013, 03:53 PM
#2
Lively Member
Re: Shortest distance on a circle formula required
Function Clockwise(intA as integer, intB as integer) As boolean
If intB - intA >= 180
Clockwise = True
Else
Clockwise = False
End If
End Function
This is just me typing ,,, I think this would work?
-
Jul 26th, 2013, 04:47 PM
#3
Re: Shortest distance on a circle formula required
I reckon that if you measure the angles in radians, and scale the result of their subtraction by divisions with PI to be in the range [0;PI[ (positive modulo with real numbers), you will get the shortest distance between the angles on a unit circle. This value can ofc be scaled for larger circles by multiplying the radius.
This is just from the top of my head though - but something along those lines ought to work - Article on Radians
Regards
Tom
In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)
-
Jul 26th, 2013, 04:49 PM
#4
Thread Starter
New Member
Re: Shortest distance on a circle formula required
Originally Posted by tylerpestell
Function Clockwise(intA as integer, intB as integer) As boolean
If intB - intA >= 180
Clockwise = True
Else
Clockwise = False
End If
End Function
This is just me typing ,,, I think this would work?
sorry does not work as it will give me always only one direction
-
Jul 26th, 2013, 05:27 PM
#5
Re: Shortest distance on a circle formula required
Assuming your angles are in degrees, this will work:
Code:
A = (A + 360) Mod 360
B = (B + 360) Mod 360
Dim C = B - A
Clockwise = C <= 180 AndAlso C > 0 ' OrElse C = -180
This gives the right results even when A or B is <0 or >360.
The reason for the optional last term (commented out) is that when A=-180 and B=0 you get Clockwise = False. But when A=0 and B =180 it's True. Now maybe you don't care which way it goes when the difference is exactly 180, in which case you can leave out the last term. But if you would like the direction to default to Clockwise whenever the difference is 180, you should include it.
BB
Last edited by boops boops; Jul 26th, 2013 at 06:44 PM.
-
Jul 26th, 2013, 05:33 PM
#6
Lively Member
Re: Shortest distance on a circle formula required
Originally Posted by john adams
sorry does not work as it will give me always only one direction
Why would it only give you one direction?
Clockwise equaling false is how I would know to go Counter Clockwise ;-)
If you want more help you need to provide more details or some of your code.
-
Jul 26th, 2013, 07:20 PM
#7
Re: Shortest distance on a circle formula required
Originally Posted by tylerpestell
Why would it only give you one direction?
Clockwise equaling false is how I would know to go Counter Clockwise ;-)
If you want more help you need to provide more details or some of your code.
The problem isn't that it always goes one way, but that it sometimes goes the wrong way.
Suppose intA=0 and intB=1. Your code will give intB - intA =1, which is less than 180. So Clockwise is false. Now you have to go anticlockwise 359 degrees instead of clockwise 1 degree. Maybe you meant to write
Code:
If intB - intA <= 180
Now suppose intA = 359 and intB = 358. The difference will be -1, which is less than 180, so you will get Clockwise = True. Now you will end up going 359 degrees clockwise instead of 1 degree anticlockwise.
BB
-
Jul 27th, 2013, 11:34 AM
#8
Lively Member
Re: Shortest distance on a circle formula required
Originally Posted by boops boops
The problem isn't that it always goes one way, but that it sometimes goes the wrong way.
Suppose intA=0 and intB=1. Your code will give intB - intA =1, which is less than 180. So Clockwise is false. Now you have to go anticlockwise 359 degrees instead of clockwise 1 degree. Maybe you meant to write
Code:
If intB - intA <= 180
Now suppose intA = 359 and intB = 358. The difference will be -1, which is less than 180, so you will get Clockwise = True. Now you will end up going 359 degrees clockwise instead of 1 degree anticlockwise.
BB
If A is 0 and B is 1 wouldn't you want to go anticlockwise? It has been a LONG time since school but maybe I got my circle and degrees messed up ... don't you start 0 on the x-axes on the right side of the y-axis and 180 is on the left? In which case to bring 0 to 1 you would want to go anticlockwise? As for the A being greater I just assumed A was always smaller ( bad to assume I know) Your approach is obviously much better but I did only spend like 2 seconds thinking about it :-D .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|