How do I find angle of a line?

  • Thread starter Thread starter Jem
  • Start date Start date
J

Jem

Hi all

I have the following code which draws a vertical line on a form...
Dim VertCrossHairX1 As Integer = 75

Dim VertCrossHairX2 As Integer = 75

Dim VertCrossHairY1 As Integer = 70

Dim VertCrossHairY2 As Integer = 80

MyGraphics.DrawLine(RedPen, x1:=VertCrossHairX1, y1:=VertCrossHairY1,
x2:=VertCrossHairX2, y2:=VertCrossHairY2)
By altering the values in the variablesI am able to rotate this line. The
question is - How do I obtain the angle of the line each time it is rotated
to a different angle? I would like the variable 'Angle' to store this value
for use in a calculation.

I'm a very novice prgrammer and would appreciate any help/guidance as to how
to go about this.

Many Thanks

Jem
 
Jem said:
I have the following code which draws a vertical line on a form...
Dim VertCrossHairX1 As Integer = 75
Dim VertCrossHairX2 As Integer = 75
Dim VertCrossHairY1 As Integer = 70
Dim VertCrossHairY2 As Integer = 80

By altering the values in the variablesI am able to rotate this line.
The question is - How do I obtain the angle of the line each time it
is rotated to a different angle? I would like the variable 'Angle'
to store this value for use in a calculation.

Angle=Math.Atan2(VertCrossHairY2-VertCrossHairY1,
VertCrossHairX2-VertCrossHairX1)

(I might have the 1 and 2 round the wrong way).

Note that gives the angle in radians. You may want to convert to degrees.
And strictly speaking, a line does not intrinsically have an angle - it has
an angle /relative to something else/, which may be why your googling didn't
produce a useful result.

HTH

Andrew
 
Thanks Andrew

For some reason i'm not quite getting the result I require. I'm not quite
sure what i'm doing wrong. If I either post or email the code would you
have a look at it for me?

I did a little bit of programming in VB6 quite a few years ago (a VERY
little bit!) and am trying to update a couple of calculation programs for
use on a Pocket PC. I seem to be spending hours on trying to get the
simplist things to work and my 48 yr old brain is struggling to keep up with
the progression of the language!


As i've already stated, i'm still very new to VB.Net and my code is probably
very poor. Also, i've probably gone about things in completely the wrong
way, but I am trying to learn as I go ;-)

Cheers

Jem
 
Jem said:
Thanks Andrew

For some reason i'm not quite getting the result I require.

It would probably be best if you told us the result you require... ;-)
I'm not
quite sure what i'm doing wrong. If I either post or email the code
would you have a look at it for me?

I too am new to VB.NET, and I'm [meant to be] busy at the moment, so just
post it here.

Andrew
 
Thanks Andrew.

Sorry, I panicked a bit!

Firstly my maths was a bit rusty (30 odd years since I was in school!) and I
made a mistake in the Radians to degrees calc. Then I needed to changed
some values - a quick mulitiplication by -1 sorted that. I think i'm sort
of 'back on track' now. Watch this space ;-)

Cheers

Jem



Andrew Morton said:
Jem said:
Thanks Andrew

For some reason i'm not quite getting the result I require.

It would probably be best if you told us the result you require... ;-)
I'm not
quite sure what i'm doing wrong. If I either post or email the code
would you have a look at it for me?

I too am new to VB.NET, and I'm [meant to be] busy at the moment, so just
post it here.

Andrew
 
Back
Top