1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Port of `three.js/src/math/Cylindrical.js`.
use super::Vector3;
/// Represents points in 3D space as cylindrical coordinates.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Cylindrical {
/// The distance from the origin to a point in the x-z plane.
pub radius: f64,
/// A counterclockwise angle in the x-z plane measured in radians from the positive z-axis.
pub theta: f64,
/// The height above the x-z plane.
pub y: f64,
}
impl Default for Cylindrical {
/// `new Cylindrical()`: radius 1, theta 0, y 0.
fn default() -> Self {
Self::new(1.0, 0.0, 0.0)
}
}
impl Cylindrical {
/// `new Cylindrical( radius, theta, y )`.
pub const fn new(radius: f64, theta: f64, y: f64) -> Self {
Self { radius, theta, y }
}
/// `Cylindrical.set()`.
pub fn set(&mut self, radius: f64, theta: f64, y: f64) -> &mut Self {
self.radius = radius;
self.theta = theta;
self.y = y;
self
}
/// `Cylindrical.copy()`.
pub fn copy(&mut self, other: &Self) -> &mut Self {
self.radius = other.radius;
self.theta = other.theta;
self.y = other.y;
self
}
/// `Cylindrical.setFromVector3()`.
pub fn set_from_vector3(&mut self, v: &Vector3) -> &mut Self {
self.set_from_cartesian_coords(v.x, v.y, v.z)
}
/// `Cylindrical.setFromCartesianCoords()`.
pub fn set_from_cartesian_coords(&mut self, x: f64, y: f64, z: f64) -> &mut Self {
self.radius = (x * x + z * z).sqrt();
self.theta = x.atan2(z);
self.y = y;
self
}
}