20 lines
352 B
Rust
20 lines
352 B
Rust
use cgmath::{Angle, Point2, Rad, Vector2};
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct Polar {
|
|
pub center: Point2<f32>,
|
|
pub radius: f32,
|
|
pub angle: Rad<f32>,
|
|
}
|
|
|
|
impl Polar {
|
|
pub fn to_cartesian(self) -> Point2<f32> {
|
|
let v = Vector2 {
|
|
x: self.radius * self.angle.sin(),
|
|
y: self.radius * self.angle.cos(),
|
|
};
|
|
|
|
return self.center + v;
|
|
}
|
|
}
|