0

Suppose a given azimuth angle is calculated due east counter clockwise (ccw), and I want to convert it to due north clockwise, so I found the following formula,

# limit the range to 0..360:
r.mapcalc "angle_cw = (450 - angle_ccw) % 360"

now if I want to keep it between -180 to +180 I used the following formula,

# limit the range to -180..180 (again, clockwise from North):
r.mapcalc "angle_cw = (630 - angle_ccw) % 360 - 180"

I want a clear explanation how these two formula actually work, so that I can write due south clockwise azimuth angle conversion formula as well while due east counter clockwise angle is given.

2
  • 1
    Have you tried working out samples which exercise the math? There are only two variables in play (zero point and direction). Constant covers one and sign covers the other.
    – Vince
    May 14, 2018 at 0:36
  • if you know the math could you please share the link or the description? May 14, 2018 at 8:56

2 Answers 2

1

1) see Convert counter-clockwise angle to clockwise one

in R:

Counter clockwise (0 = East)

> theta = 192

enter image description here

Clockwise (0 = Nord)

> (-theta + 90)%%360
[1] 258
> (-theta + 90)%%180
[1] 78

enter image description here

And Counter clockwise with 0 = South

> (theta + 90)%%360
[1] 282
> (theta + 90)%%180
[1] 102

enter image description here

Same in Python

theta = 192
(-theta+90)%360
258
(-theta+90)%180
78
(theta+90)%360
282
(theta+90)%180
 102

2) If you want the explanation of the +450 solution , see the comments of R: How do I easily convert a line angle to a navigational-bearing scale for example.

2
  • very interesting! Thank you so much! but when you do (mod 180) the value remains between 0 to 180. but i want a range from -180 to + 180. how can i achieve this using the same logic you used? May 14, 2018 at 21:51
  • (( theta + 180 )%360 ) - 180
    – gene
    May 15, 2018 at 15:24
0

Finally I figured it out, the following r code converts due East counter clock wise angle to the followings, please comment

 
cwN_180 - due north clockwise limited -180 to +180
cwS_180 - due south clockwise limited -180 to +180
cwN_360 - due north clockwise limited 0 to +360
cwS_360 - due south clockwise limited 0 to +360

 
cwN_180 <- function(ccwE){
  cwN = ((630 - ccwE) %% 360.0) - 180.0
  return(cwN)
}

cwS_180 <- function(ccwE){ cwN = ((450 - ccwE) %% 360.0) - 180.0 return(cwN) }

cwS_360 <- function(ccwE){ cwN = (270 - ccwE) %% 360 return(cwN) }

cwN_360 <- function(ccwE){ cwN = (450 - ccwE) %% 360 return(cwN) }

cwS360 <- cwS_360(192.0) cwS360 cwN360 <- cwN_360(192.0) cwN360 cwN180 <- cwN_180(192.0) cwN180 cwS180 <- cwS_180(192.0) cwS180

output:

cwS360 <- cwS_360(192.0) cwS360 [1] 78 cwN360 <- cwN_360(192.0) cwN360 [1] 258 cwN180 <- cwN_180(192.0) cwN180 [1] -102 cwS180 <- cwS_180(192.0) cwS180 [1] 78

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.