Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have a question about how the calculate angles between coordinates / lines.
I have four labels filled with XY coordinates comma delimited.
Which C# code should I use to get the desired value in Label_Angle_Result

Preferred route
Fixed Point A . Label_FP_A . X,Y
Fixed Point B . Label_FK_B . X,Y

Measured point of GPS
GPS Point A . Label_GPS_A . X,Y
GPS Point B . Label_GPS_B . X,Y

Result
Angle Label_Angle_Result . number

What I have tried:

I look in the CAD solutions but I have not found anything good here in connection..
Posted
Updated 20-Jun-16 0:33am
v3
Comments
BillWoodruff 20-Jun-16 7:09am    
are you working with a "flat space," or some form of projection (mercator, spherical, etc.) ? An angle value makes "sense" only when you know the structure of the co-ordinate system that is the context in which the angle exists.
RedDk 20-Jun-16 11:50am    
See haversine formula ...

1 solution

As you have 3 components we are talking about vectors in the 3D space (Why?)...
To calculate the angle you have to know two things:

1. Dot product of two vectors...
$\vec{a} \cdot \vec{b}$

Which is
$(a_{x} + a_{y} + a_{z}) \times (b_{x} + b_{y} + b_{z})$


2. The magnitude of the vectors...
$\parallel \vec{a} \parallel$

Which is
$\sqrt{a_{x}^{2} + a_{y}^{2} + a_{z}^{2}}$


Then you can compute the cosinus of the angle, which is reversible...
$\cos(\theta) = \frac{\vec{a} \cdot \vec{b}} { ||\vec{a}|| \times ||\vec{b}||}$


---

In 2D space it is much more simple:
$\cos(\theta) = \vec{a} \cdot \vec{b}$
 
Share this answer
 
v12
Comments
MaikelO1 20-Jun-16 6:33am    
Stom! ik werk in WGS84 dat is 2D..
Kornfeld Eliyahu Peter 20-Jun-16 6:41am    
I'm definitely stupid not noticing that...So obvious form your sample...
I'm so stupid that I even know that the cosinus of the angle between two 2D vectors is the dot product of the vectors...(see above)
MaikelO1 20-Jun-16 7:12am    
forgot to translate, sorry .. " stupid of me, I work in WGS84 so I have then no z value" tnxs for your help
CPallini 22-Jun-16 2:34am    
5.
Kornfeld Eliyahu Peter 22-Jun-16 2:36am    
Thank you...
(It should go to Chris, who fixed the math in less than 24 hours...)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900