|
-
Aug 31st, 2008, 06:55 PM
#1
Thread Starter
Member
-
Aug 31st, 2008, 07:07 PM
#2
Re: Finding an Angle
Well, first you need the lengths of the sides of the triangle:
diffX = abs(X1-X2)
diffY = abs(Y1-Y2)
Now, the Tangent of the angle is equal to diffY (opposite side) / diffX (adjacent side). So if you take the ArcTan of (diffY/diffX), you will get a number that will be the angle in radians. To turn that into degrees, multiply by 180 and divide by pi. Thus, the whole equation looks like:
angle in degrees = (180 * Math.ATan(math.abs((Y1-Y2)/(X1-X2))))/3.1415
That will get you pretty close. A more accurate value for pi would give you more significant figures, but this will get you accurate to about three decimal places.
My usual boring signature: Nothing
 
-
Sep 1st, 2008, 06:33 PM
#3
Thread Starter
Member
Re: Finding an Angle
I don't seem to beable to get it working Could you show me a little Example..
uhm, it wasn't me..
Prove it..
Prove it was me........
-
Sep 1st, 2008, 06:53 PM
#4
Re: Finding an Angle
How about you show us your attempt?
-
Sep 1st, 2008, 06:58 PM
#5
Thread Starter
Member
Re: Finding an Angle
Don't Know what your Trying to Imply on me there but I'm not too Good at maths..or Angles..and here's what i got..It doesn't Return the Right Value..From the Center of the Form, to the Cursor Position.
Code:
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim Angle As Double
Angle = (180 * Math.Atan(Math.Abs((Cursor.Position.Y - Me.Height / 2) / (Cursor.Position.X - Me.Width / 2)))) / 3.1415
Label2.Text = Angle
End Sub
uhm, it wasn't me..
Prove it..
Prove it was me........
-
Sep 1st, 2008, 07:33 PM
#6
Re: Finding an Angle
You need to be aware that the positive Y direction on your form is downwards, where your calculations are assuming that it's upwards.
You should also be aware that the middle of the form's client area, which excludes the border and title bar, would be found using the ClientSize, not the Height and Width.
You should also be using the Math.PI constant to convert radians to degrees.
-
Sep 1st, 2008, 08:00 PM
#7
Re: Finding an Angle
Another point to note, which I forgot to mention, is that Cursor.Position is in screen coordinates, not form coordinates.
I would suggest that you start off by making sure you can calculate the correct opposite and adjacent values before you worry about anything else. ALWAYS break your problem down and solve the first bits first. The PointToClient method of your form will be useful.
-
Sep 1st, 2008, 08:21 PM
#8
Re: [RESOLVED] Finding an Angle
You should also note that you're never going to get an angle outside the of 0-90 the way you're doing it. You'd have to use the signs of the opposite and adjacent sides specifically to determine which quadrant you're in.
-
Sep 1st, 2008, 08:24 PM
#9
Re: [RESOLVED] Finding an Angle
Hmmm... I see that this thread is now resolved. It's customary to provide the final solution for those who may have the same question in future. It's also considered polite to tell people that the problem is solved and thanks for the help.
-
Sep 2nd, 2008, 09:29 AM
#10
Re: [RESOLVED] Finding an Angle
I would guess that a combination of your post #6 and #8 solved the issue.
My usual boring signature: Nothing
 
-
Sep 2nd, 2008, 09:31 AM
#11
Thread Starter
Member
Re: [RESOLVED] Finding an Angle
Sorry i didn't reply..I ended up asking a Friend on MSN..He let me use some Code of his..
uhm, it wasn't me..
Prove it..
Prove it was me........
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
|