|
-
Nov 5th, 2005, 06:22 PM
#1
Re: Calculating the angle of a Line in a circle
Or swap x2 and x1 of x2>x1, and the same for y
-
Nov 5th, 2005, 06:30 PM
#2
Thread Starter
Fanatic Member
Re: Calculating the angle of a Line in a circle
 Originally Posted by dglienna
Or swap x2 and x1 of x2>x1, and the same for y
I tried this also and I get the same exact thing for whichever I try
-
Nov 5th, 2005, 08:27 PM
#3
Re: Calculating the angle of a Line in a circle
VB Code:
Private Function GetAngle(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long) As Double
Dim PI As Double
Dim theta As Double
Dim deltaX As Long
Dim deltaY As Long
'get angle of line in radians
'deltay/deltax = tan(angle)
deltaY = Y1 - Y2
deltaX = X2 - X1
PI = Atn(1) * 4
'adjust to our coordinate system
If deltaX = 0 Then
'fix division by zero errors
If Y1 > Y2 Then
theta = 180
Else
theta = 90
End If
ElseIf deltaX > 0 And deltaY >= 0 Then '1st quadrant
theta = Atn((Y1 - Y2) / (X2 - X1))
ElseIf deltaX < 0 And deltaY >= 0 Then '2nd quadrant
theta = Atn((Y1 - Y2) / (X2 - X1)) + PI
ElseIf deltaX < 0 And deltaY < 0 Then '3rd quadrant
theta = Atn((Y1 - Y2) / (X2 - X1)) + PI
ElseIf deltaX > 0 And deltaY < 0 Then '4th quadrant
theta = Atn((Y1 - Y2) / (X2 - X1)) + 2 * PI
End If
'convert to degrees
'there are 180 degrees per PI radians
'if theta < 0 then theta =
GetAngle = theta * 180 / PI
End Function
-
Nov 5th, 2005, 08:35 PM
#4
Thread Starter
Fanatic Member
Re: Calculating the angle of a Line in a circle
great thanks moeur
-
Nov 5th, 2005, 08:35 PM
#5
Re: Calculating the angle of a Line in a circle
moeur, could you possible explain that? I thought that it had something to do with quadrants, but didn't want to try to guess at the answer. If not, that's ok, also. I was thinking that 0 degrees was at 9'oclock, and that was the issue. Maybe I was close.
-
Nov 5th, 2005, 09:15 PM
#6
Re: Calculating the angle of a Line in a circle(resolved)
The problem is how the ArcTangent is defined
-90° < Atn(x) < 90°
for
-infinity < x < infinity
But that is not what we wanted so I had to adjust
Last edited by moeur; Nov 6th, 2005 at 01:09 AM.
-
Nov 5th, 2005, 09:44 PM
#7
Re: Calculating the angle of a Line in a circle(resolved)
Well, I wish that I could have seen an explanation, but I found this link, and it didn't help much.
http://mathworld.wolfram.com/InverseTangent.html
I looked up tangent, and saw the same images.
http://mathworld.wolfram.com/Tangent.html
I guess I don't know what I'm looking at.
I used to know the formula to draw a circle with COS and SIN, so thought this wouldn't be too hard to grasp
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
|