Skip to main content

cad_cs/libs/cs/core/
d3.rs

1// 📃 ./src/libs/cs/core/d3.rs
2
3use crate::libs::cs::{
4	abstracts::AbstractProjectionsCs3,
5	model::{Cs, *},
6	types::Cs3,
7};
8
9// --- IMPLEMENTACJE FROM (DTO -> Cs3) ---
10
11impl From<CoordsXyz> for Cs3 {
12	/// 📚 【 POL】: Konwertuje kartezjańskie DTO XYZ na wektor Cs3.
13	/// 📚 【 ENG】: Converts Cartesian XYZ DTO to a Cs3 vector.
14	#[inline]
15	fn from(c: CoordsXyz) -> Self { Cs([c.x, c.y, c.z]) }
16}
17
18impl From<CoordsCylindricalZ> for Cs3 {
19	/// 📚 【 POL】: Konwertuje współrzędne cylindryczne względem osi Z na wektor kartezjański Cs3.
20	/// 📚 【 ENG】: Converts cylindrical coordinates relative to the Z-axis to a Cs3 Cartesian vector.
21	#[inline]
22	fn from(c: CoordsCylindricalZ) -> Self {
23		let (sin_f, cos_f) = c.f_y_x.sin_cos();
24		Cs([c.r_d2 * cos_f, c.r_d2 * sin_f, c.z])
25	}
26}
27
28impl From<CoordsCylindricalY> for Cs3 {
29	/// 📚 【 POL】: Konwertuje współrzędne cylindryczne względem osi Y na wektor kartezjański Cs3.
30	/// 📚 【 ENG】: Converts cylindrical coordinates relative to the Y-axis to a Cs3 Cartesian vector.
31	#[inline]
32	fn from(c: CoordsCylindricalY) -> Self {
33		let (sin_f, cos_f) = c.f_z_x.sin_cos();
34		Cs([c.r_d2 * cos_f, c.y, c.r_d2 * sin_f])
35	}
36}
37
38impl From<CoordsCylindricalX> for Cs3 {
39	/// 📚 【 POL】: Konwertuje współrzędne cylindryczne względem osi X na wektor kartezjański Cs3.
40	/// 📚 【 ENG】: Converts cylindrical coordinates relative to the X-axis to a Cs3 Cartesian vector.
41	#[inline]
42	fn from(c: CoordsCylindricalX) -> Self {
43		let (sin_f, cos_f) = c.f_z_y.sin_cos();
44		Cs([c.x, c.r_d2 * cos_f, c.r_d2 * sin_f])
45	}
46}
47
48impl From<CoordsSpherical> for Cs3 {
49	/// 📚 【 POL】: Konwertuje współrzędne sferyczne na wektor kartezjański Cs3.
50	/// 📚 【 ENG】: Converts spherical coordinates to a Cs3 Cartesian vector.
51	#[inline]
52	fn from(c: CoordsSpherical) -> Self {
53		let (sin_f, cos_f) = c.f_y_x.sin_cos(); // Azymut XY
54		let (sin_t, cos_t) = c.t_z_r.sin_cos(); // Inklinacja Z do R
55		Cs([c.r_d3 * sin_t * cos_f, c.r_d3 * sin_t * sin_f, c.r_d3 * cos_t])
56	}
57}
58
59impl AbstractProjectionsCs3 for Cs<3> {
60	/// 📚 【 POL】: Tworzy nowy wektor Cs3 z układu sferycznego (R, Φ, Θ).
61	/// 📚 【 ENG】: Creates a new Cs3 vector from a spherical system (R, Φ, Θ).
62	#[rustfmt::skip] #[inline]
63	fn new_from_rft(r: f64, phi_rad: f64, theta_rad: f64) -> Self {
64		let (sin_phi, cos_phi) = phi_rad.sin_cos();
65		let (sin_theta, cos_theta) = theta_rad.sin_cos();
66		Cs([r * sin_theta * cos_phi, r * sin_theta * sin_phi, r * cos_theta])
67	}
68
69	/// 📚 【 POL】: Interpretuje Cs3 jako kontener sferyczny [R, Φ, Θ] i zwraca wektor kartezjański [X, Y, Z].
70	/// 📚 【 ENG】: Interprets Cs3 as a spherical container [R, Φ, Θ] and returns a Cartesian vector [X, Y, Z].
71	#[rustfmt::skip] #[inline]
72	fn new_as_xyz_from_rft(&self) -> Cs<3> {
73		let (sin_phi, cos_phi) = self.0[1].sin_cos();
74		let (sin_theta, cos_theta) = self.0[2].sin_cos();
75		Cs([
76			self.0[0] * sin_theta * cos_phi,
77			self.0[0] * sin_theta * sin_phi,
78			self.0[0] * cos_theta
79		])
80	}
81
82	/// 📚 【 POL】: Tworzy nowy wektor 3D z układu cylindrycznego względem osi Z: (R_xy, Φ, Z).
83	/// 📚 【 ENG】: Creates a new 3D vector from a cylindrical system relative to the Z-axis: (R_xy, Φ, Z).
84	#[rustfmt::skip] #[inline]
85	fn new_from_rfz(r_d2: f64, phi_rad: f64, z: f64) -> Self {
86		let (sin_phi, cos_phi) = phi_rad.sin_cos();
87		Cs([r_d2 * cos_phi, r_d2 * sin_phi, z])
88	}
89
90	/// 📚 【 POL】: Tworzy nowy wektor 3D z układu cylindrycznego względem osi X: (R_yz, Φ, X).
91	/// 📚 【 ENG】: Creates a new 3D vector from a cylindrical system relative to the X-axis: (R_yz, Φ, X).
92	/// ⚙️ 【 POL】: Kąt Φ mierzony jest od osi Y do Z na płaszczyźnie YZ.
93	/// ⚙️ 【 ENG】: Angle Φ is measured from the Y-axis to the Z-axis on the YZ plane.
94	#[rustfmt::skip] #[inline]
95	fn new_from_rfx(r_d2: f64, phi_rad: f64, x: f64) -> Self {
96		let (sin_phi, cos_phi) = phi_rad.sin_cos();
97		Cs([x, r_d2 * cos_phi, r_d2 * sin_phi])
98	}
99
100	/// 📚 【 POL】: Tworzy nowy wektor 3D z układu cylindrycznego względem osi Y: (R_xz, Φ, Y).
101	/// 📚 【 ENG】: Creates a new 3D vector from a cylindrical system relative to the Y-axis: (R_xz, Φ, Y).
102	/// ⚙️ 【 POL】: Kąt Φ mierzony jest od osi X do Z na płaszczyźnie XZ.
103	/// ⚙️ 【 ENG】: Angle Φ is measured from the X-axis to the Z-axis on the XZ plane.
104	#[rustfmt::skip] #[inline]
105	fn new_from_rfy(r_d2: f64, phi_rad: f64, y: f64) -> Self {
106		let (sin_phi, cos_phi) = phi_rad.sin_cos();
107		Cs([r_d2 * cos_phi, y, r_d2 * sin_phi])
108	}
109}