473,396 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I find angle of a line?

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
Jan 16 '07 #1
4 6343
Jem wrote:
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
Jan 16 '07 #2
Jem
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
"Andrew Morton" <ak*@in-press.co.uk.invalidwrote in message
news:OW**************@TK2MSFTNGP03.phx.gbl...
Jem wrote:
>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

Jan 16 '07 #3
Jem wrote:
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
Jan 16 '07 #4
Jem
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" <ak*@in-press.co.uk.invalidwrote in message
news:O9*************@TK2MSFTNGP04.phx.gbl...
Jem wrote:
>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

Jan 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mxsmanic | last post by:
I have a line like this in some PHP code on my Web page: $callthis =~ s/<*>//g; When the page runs, I get this error: Parse error: parse error, unexpected '<' in /Feedback.php on line 145 ...
5
by: Darren Grant | last post by:
Hi there, I've attempted to implement an Angle class. An Angle is a subset of an integer, where the range is [0,360). All other operations should be permitted. The code works, I think......
3
by: Lasse Eskildsen | last post by:
Hi, I'm trying to measure an angle of a triangle in vb.net, but I'm not getting it right. This is my triangle (kind of): A l\ 1 \ 1 \
3
by: Doraj | last post by:
Hello ! Here is my problem : I had some php scripts which worked well with php 4.0.5 (GD 1.6.2 according to phpinfo() ) and i put them on a new server with php 4.4.2 (and GD 2.0.28). Now,...
19
by: Killer42 | last post by:
Hi all. Sorry to be brief, but have to leave. If I have the coordinates of two points (on the computer screen), how do I calculate the angle of the line which joins them? I know, my terms...
2
by: laredotornado | last post by:
Hi, I'm using php 4.4.4. Maybe I'm misreading the docs, but in the imagettfbbox manual (http://us2.php.net/imagettfbbox), it says that text coordinates are the same regardless of what the angle...
3
by: chemicalcold0 | last post by:
Hi there, since < has a meaning in c# for regular expressions and \< says it's an unrecognized escape sequence, I'm pretty lost parsing html tags without replacing them first with another...
1
by: szepesg | last post by:
Dear Readers, The word "hide" appeares in a text several times. I want find one of them and then before it I want ot find the nearest unangle bracketed area to it (so an area without angle...
5
by: mvjohn100 | last post by:
Hello, For Drawing a angled line using the MFC function pDC->AngleArc(cStart.x,cStart.y,AngLineLength,Angle,0) but for storing the line I want to know the end point of the line. how can I find...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.