Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lines

Status
Not open for further replies.

SteveD73

Programmer
Jan 5, 2001
109
GB
Hello

Can anyone answer the following question:

I have 2 lines with the following coords

line 1 (x1, y1) - (x2, y2)
line 2 (x1, y1) - (x3, y3)

How can I calculate the angle between them?

Thanks
 
For two Vectors v1(x1, y1, z1) and v2(x2, y2, z2):

cos(v1, v2) = (x1*x2 + y1*y2 + z1*z2)/(sqrt(x1*x1 + y1*y1 + z1*z1) *sqrt(x2*x2 + y2*y2 + z2*z2));
 
I've tried the above formulae with no success. If the coords of the lines are

(0, 0) - (10, -10)
(0, 0) - (10, 10)

The angle should be 45. However, the first part of equation (x1*x2 + y1*y2 + z1*z2) results in 0.

0/x = 0

Any sugestions on where im going wrong?

Thanks
 
as I see, there is 90 degrees, not 45. 45 are relative to OX or to OY, but not between themselves. Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top