Click to See Complete Forum and Search --> : How To calculate the startangle and endangle in arc?
Chozhan
Mar 30th, 2010, 04:20 AM
Consider
starting Point (x1,y1) where x1=-3.227 y1=5.615
Ending Point(x2,y2) where x2=-3.137y2=5.466
Center Point(Xc,Yc) where xc=-3.18 and yc=5.54
I know the above startingpoint, endingpoint and center point I want to calculate the radius ,startangle and endangle.
startangle should be 121.156
endangle should be 301.156
How to obtain the above startangle and endangle?
baja_yu
Mar 30th, 2010, 04:22 AM
If you know the math to do it on paper (which I don't) it will be very easy to translate that into VB code.
Chozhan
Mar 30th, 2010, 04:31 AM
I am not Strong in Maths..
si_the_geek
Mar 30th, 2010, 05:30 AM
Neither are most programmers I'm afraid... your best bet is to research the maths part on the internet, and then ask us how to convert it in to code.
AsmIscool
Mar 30th, 2010, 06:06 AM
Shouldn't this be moved to the maths forum? http://www.vbforums.com/forumdisplay.php?f=20 At least they don't run away from things like this over there.
si_the_geek
Mar 30th, 2010, 06:18 AM
Good point... thread moved to Maths forum
jemidiah
Mar 30th, 2010, 05:39 PM
It's actually pretty easy with a little trig (which, conveniently, other people have figured out how to code well over the years). From your input numbers, it seems that you're measuring degrees starting straight east, going counterclockwise. This is the standard convention.
The radius is just r = Sqrt((xc - xi)^2 + (yc - yi)^2) where you can use either (xi, yi) = (x1, y1) or (x2, y2) and the answer will be the same, up to rounding errors. In your example, the radius is 0.0885 using (x1, y1) or 0.0856 using (x2, y2). Since these aren't really that close, you probably haven't kept enough significant digits around--that is, you rounded too early when writing down your results. This makes sense since your numbers terminate at the 2nd or 3rd decimal digit, while the radius starts at the 2nd decimal digit.
The angle is only slightly more involved. It can be calculated using atan2 (http://en.wikipedia.org/wiki/Atan2), which is a built-in function in some languages. I'm using Python 2.5 and the math module has atan2, for instance. In this case, your angles are exactly atan2(yi-yc, xi-xc). This will usually give you back results in radians, which need to be converted to degrees by multiplying by 180/pi. Note: sometimes, you'll get negative angles back. However, remember that if you rotate an extra 360 degrees, you'll end up where you started, so just add 360 degrees.
In your example, I found that math.atan2(y1-yc, x1-xc) * 180 / math.pi = 122.07 degrees. Again, this is probably slightly off due to rounding errors. I also found that math.atan2(y2-yc, x2-xc) * 180 / math.pi = -59.84 degrees. Adding 360 degrees, this becomes 300.16 degrees, which is correct up to roundoff.
I can derive atan2 for you if you're really curious, though it's online in many places as well. It just requires some reasoning by cases and some basic trigonometry. The radius formula I gave is a slight rearrangement of the Pythagorean Theorem, which has hundreds of derivations in existence.
Chozhan
Apr 5th, 2010, 05:35 AM
Thanks for your help.. Can You give me the code for Atan2 ..
Chozhan
Apr 5th, 2010, 05:46 AM
i am using atan2 function but i am doubt it is not giving correct..
the code which i used ..
If y > 0 Then
If x >= y Then
Atan21 = Atn(y / x)
ElseIf x <= -y Then
Atan21 = Atn(y / x) + Pi
Else
Atan21 = Pi / 2 - Atn(x / y)
End If
Else
If x >= -y Then
Atan21 = Atn(y / x)
ElseIf x <= y Then
Atan21 = Atn(y / x) - Pi
Else
Atan21 = -Atn(x / y) - Pi / 2
End If
End If
jemidiah
Apr 5th, 2010, 08:11 AM
I have no idea how you got that code. It's wrong in most of the ways it could be wrong; the most correct thing about it is that it has some cases and throws Atn(y / x) in there.... Anyway, I transcribed the definition given from the Wikipedia article I linked into VB6 code. It might well be the same in .NET, though I don't use .NET. I checked it against input distributed across the unit circle and got correct results.
Private Const PI = 3.14159265
Private Function atan2(y As Single, x As Single) As Single
If x > 0 Then
atan2 = Atn(y / x)
ElseIf x < 0 Then
If y >= 0 Then
atan2 = PI + Atn(y / x)
Else 'y < 0
atan2 = -PI + Atn(y / x)
End If
Else 'x = 0
If y > 0 Then
atan2 = PI / 2
ElseIf y < 0 Then
atan2 = -PI / 2
Else 'y = 0
MsgBox "Whoops. You missed an edge case."
atan2 = 0
End If
End If
'Make the routine slightly nicer; keep angles of 0 to 2 PI outputting in that interval
If atan2 < 0 Then atan2 = atan2 + 2 * PI
End Function
To be honest, I think you should be able to make this routine from the Wikipedia article. I was curious and searched for the routine briefly and found some promising hits in a few seconds as well, so you probably didn't search for it. Honestly, I wrote the above code for the convenience of people who read this thread in the future since I recently ran into an issue when someone could have saved me a fair bit of hassle by posting some code.
Chozhan
Apr 6th, 2010, 06:26 AM
thank you for your guide.
still Angles are varying from one to another ..how to calculate exact one.
boops boops
Apr 8th, 2010, 07:16 PM
dotNet has Math.Atan2 built in. BB
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.