light-control/src/util.rs

19 lines
377 B
Rust

use cgmath::Vector2;
pub fn get_angle(p: &Vector2<f32>) -> f32 {
let pi=3.1415926;
let pi2 = 2.0*pi;
if p.x < 0.0 {
(p.y / p.x).atan() / pi2 + 0.75
} else if p.x == 0.0 && p.y == 0.0 {
0.0
} else {
if p.y < 0.0 {
(-p.x / p.y).atan() / pi2
} else {
(p.y / p.x).atan() / pi2 + 0.25
}
}
}