Angle difference between two bearings: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (Added Arturo implementation) |
No edit summary |
||
Line 3,828: | Line 3,828: | ||
-161.50295230785 |
-161.50295230785 |
||
37.2988555882</pre> |
37.2988555882</pre> |
||
=={{header|Vlang}}== |
|||
{{trans|go}} |
|||
<lang vlang>import math |
|||
type Bearing = f64 |
|||
const test_cases = [ |
|||
[Bearing(20), 45], |
|||
[Bearing(-45), 45], |
|||
[Bearing(-85), 90], |
|||
[Bearing(-95), 90], |
|||
[Bearing(-45), 125], |
|||
[Bearing(-45), 145], |
|||
[Bearing(29.4803), -88.6381], |
|||
[Bearing(-78.3251), -159.036], |
|||
] |
|||
fn main() { |
|||
for tc in test_cases { |
|||
println(tc[1].sub(tc[0])) |
|||
println(angle_difference(tc[1],tc[0])) |
|||
} |
|||
} |
|||
fn (b2 Bearing) sub(b1 Bearing) Bearing { |
|||
d := b2 - b1 |
|||
match true { |
|||
d < -180 { |
|||
return d + 360 |
|||
} |
|||
d > 180 { |
|||
return d - 360 |
|||
} |
|||
else { |
|||
return d |
|||
} |
|||
} |
|||
} |
|||
fn angle_difference(b2 Bearing, b1 Bearing) Bearing { |
|||
return math.mod(math.mod(b2-b1, 360)+360+180, 360) - 180 |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
25. |
|||
25. |
|||
90 |
|||
90 |
|||
175. |
|||
175. |
|||
-175. |
|||
-175. |
|||
170 |
|||
170 |
|||
-170 |
|||
-170 |
|||
-118.1184 |
|||
-118.11840000000001 |
|||
-80.7109 |
|||
-80.71089999999998 |
|||
</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |