Nov 5th, 2005, 10:39 AM
#1
Thread Starter
Fanatic Member
Nov 5th, 2005, 11:16 AM
#2
Re: Calculating the angle of a Line in a circle
what data are you given? startpoint and end point or line?
Nov 5th, 2005, 11:18 AM
#3
Thread Starter
Fanatic Member
Re: Calculating the angle of a Line in a circle
yes? you have the starting point, ending point of the line, it's X1, X2, Y1, and Y2...
Nov 5th, 2005, 11:29 AM
#4
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
PI = Atn(1) * 4
'get angle of line in radians
'deltay/deltax = tan(angle)
theta = Atn((Y2 - Y1) / (X2 - X1))
'convert to degrees
'there are 180 degrees per PI radians
GetAngle = theta * 180 / PI
End Function
Nov 5th, 2005, 12:11 PM
#5
Re: Calculating the angle of a Line in a circle
Originally Posted by
moeur
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
PI = Atn(1) * 4
'get angle of line in radians
'deltay/deltax = tan(angle)
theta = Atn((Y2 - Y1) / (X2 - X1))
'convert to degrees
'there are 180 degrees per PI radians
GetAngle = theta * 180 / PI
End Function
umm, what is Atn function? sorry i forgot.
Nov 5th, 2005, 12:14 PM
#6
Re: Calculating the angle of a Line in a circle
got it, inverse of TANGENT!!
am i right??
Nov 5th, 2005, 12:18 PM
#7
Re: Calculating the angle of a Line in a circle
Atn is called ArcTangent (Gupta is correct)
Atn(x) is the angle who's Tangent is x
Nov 5th, 2005, 12:24 PM
#8
Re: Calculating the angle of a Line in a circle
Originally Posted by
moeur
Atn is called ArcTangent (Gupta is correct)
Atn(x) is the angle who's Tangent is x
mouer, sorry this time you confused me. is Atn different from Atn(x)??
Nov 5th, 2005, 12:28 PM
#9
Re: Calculating the angle of a Line in a circle
No, they're the same thing. He was just using it in a sentence.
Nov 5th, 2005, 12:33 PM
#10
Re: Calculating the angle of a Line in a circle
Originally Posted by
mendhak
No, they're the same thing. He was just using it in a sentence.
thnx moeur, mendhak
Nov 5th, 2005, 02:47 PM
#11
Thread Starter
Fanatic Member
Re: Calculating the angle of a Line in a circle
Moeur,
I dont think this is working correctly because this happens:
that should be 180 degrees
Attached Images
Nov 5th, 2005, 03:22 PM
#12
Re: Calculating the angle of a Line in a circle
What are your X1, Y1 and X2,Y2?
Nov 5th, 2005, 05:38 PM
#13
Thread Starter
Fanatic Member
Re: Calculating the angle of a Line in a circle
here they are
they can change when the user clicks and drags the line:
VB Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Moving Then
Line1.X2 = X
Line1.Y2 = Y
angle = GetAngle(Line1.Y2, Line1.Y1, Line1.X2, Line1.X1)
lblDegrees.Caption = angle & "°"
End If
End Sub
Attached Images
Nov 5th, 2005, 05:47 PM
#14
Re: Calculating the angle of a Line in a circle
Try putting the parameters in the right order
VB Code:
angle = GetAngle(Line1.X1, Line1.Y1, Line1.X2, Line1.Y2)
Nov 5th, 2005, 05:48 PM
#15
Thread Starter
Fanatic Member
Re: Calculating the angle of a Line in a circle
yeah that'd probably help
Nov 5th, 2005, 05:52 PM
#16
Thread Starter
Fanatic Member
Re: Calculating the angle of a Line in a circle
ok now it works better, but on the right side of 90 degrees it goes negatively...
Attached Images
Nov 5th, 2005, 06:10 PM
#17
Re: Calculating the angle of a Line in a circle
use the abs() ? even though it shouldnt return negative...
Nov 5th, 2005, 06:22 PM
#18
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:29 PM
#19
Thread Starter
Fanatic Member
Re: Calculating the angle of a Line in a circle
Originally Posted by
|2eM!x
use the abs() ? even though it shouldnt return negative...
the negative is not the only problem, when you move the line to the right of the 90 degrees it should return numbers from 91 - 180 degrees...
Nov 5th, 2005, 06:30 PM
#20
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
#21
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
#22
Thread Starter
Fanatic Member
Re: Calculating the angle of a Line in a circle
great thanks moeur
Nov 5th, 2005, 08:35 PM
#23
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
#24
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
#25
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