[R] Angle between two points with coordinates
Gwennaël Bataille
gwennael.bataille at uclouvain.be
Thu Jan 28 18:09:53 CET 2016
Dear all,
I'd like to calculate the angle from one point (origin) to another
(target), whatever their coordinates.
But I encounter some problems (detailed below). The problem could be
solved if one of you could answer positively to one of the following
questions:
1) Is there a function in R converting angles in a standardized manner?
(for example, converting -150 or 570 (=210+360) into 210)
2) If not, would you know a function arccos or arcsin returning two
different angles as an output instead of one?
Details:
I'd like to calculate the angle from one point (origin) to another
(target), whatever their coordinates.
For this, the acos and asin functions work pretty well when the end
point is located right and above the starting point (first quarter of
the trigonometric circle), but are problematic otherwise.
# In the following example, the origin is (0,0) and the target
(0.8660254, 0.5) is located at an angle of 30° :
acos( (0.8660254 - 0) )*180/pi
asin( (0.5 - 0) )*180/pi
# Both acos and asin give the same answer : 30
# If now, the origin is (0.8660254, 0.5) and the target is (0,0), the
target is located at an angle of -150° :
acos( (0 - 0.8660254) )*180/pi
asin( (0 - 0.5) )*180/pi
# Here the results are different : 150 and -30
# In fact, there are two angle solutions giving the same cosinus : 150
and -(150)
# And for sinus as well : -30 and ( 180 - (-30) ) = 210° = -150°
-acos( (0 - 0.8660254) )*180/pi
180 - asin( (0 - 0.5) )*180/pi
# But I cannot test equality between the two :
-acos( (0 - 0.8660254) )*180/pi == 180 - asin( (0 - 0.5) )*180/pi
# FALSE, since 210 != -150 (it's only the case when those two are angles)
Thank you very much in advance for your answers!
Best regards,
Gwennaël
--
Gwennaël BATAILLE, PhD student - Teaching assistant
Earth and Life Institute
Université Catholique de Louvain
1348 Louvain-la-Neuve
BELGIUM
More information about the R-help
mailing list