[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:


Given a line: (x1,y1)-(x2,y2)
given a line; (x1,0)-(x2,100)
how can i find the angle of these 2 lines?
1 Solution
It's difficult to give a definite answer to this question without knowing the coordinate system you are using.  However, in general the angle of a line is calculated as:

Radians = ArcTangent( (Y2-Y1) / (X2-X1) )

From the help:
The Atn function takes the ratio of two sides of a right triangle (number) and returns the corresponding angle in radians. The ratio is the length of the side opposite the angle divided by the length of the side adjacent to the angle.

The range of the result is -pi/2 to pi/2 radians.

To convert degrees to radians, multiply degrees by pi/180. To convert radians to degrees, multiply radians by 180/pi.
Example code:

'''Picture1.ScaleMode = 3 'Pixel
Dim X1, X2, Y1, Y2 As Double
Dim mPI As Double
Dim angle As Double
mPI = 4 * Atn(1) 'define PI
X1 = 0
Y1 = 0
X2 = 10
Y2 = 100
Picture1.Line (X1, Y1)-(X2, Y2) 'Draw the line
If X2 <> X1 Then 'Prevent division by 0
    'Calculate angle
    angle = Atn((Y2 - Y1) / (X2 - X1)) * (180 / mPI)
    angle = 90
End If
Debug.Print angle

You will have to adjust the sign of the angle depending on your coordinate system.

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now