Draws a superquadric (includes sphere, super-ellipsoid, and super-hyperboloid) # Input `c` -- (len=3) center coordinates `r` -- (len=3) radii `k` -- (len=3) exponents (must all be ≥ 0) `alpha_min` -- min α angle in [-180, 180) degrees `alpha_max` -- max α angle in (-180, 180] degrees `theta_min` -- min θ angle in [-90, 90) degrees `theta_max` -- max θ angle in (-90, 90] degrees `n_alpha` -- numb
(
&mut self,
c: &[f64],
r: &[f64],
k: &[f64],
alpha_min: f64,
alpha_max: f64,
theta_min: f64,
theta_max: f64,
n_alpha: usize,
| 306 | /// See also integration test in the **tests** directory. |
| 307 | /// |
| 308 | pub fn draw_superquadric( |
| 309 | &mut self, |
| 310 | c: &[f64], |
| 311 | r: &[f64], |
| 312 | k: &[f64], |
| 313 | alpha_min: f64, |
| 314 | alpha_max: f64, |
| 315 | theta_min: f64, |
| 316 | theta_max: f64, |
| 317 | n_alpha: usize, |
| 318 | n_theta: usize, |
| 319 | ) -> Result<(Vec<Vec<f64>>, Vec<Vec<f64>>, Vec<Vec<f64>>), StrError> { |
| 320 | if c.len() != 3 || r.len() != 3 || k.len() != 3 { |
| 321 | return Err("c.len(), r.len(), and k.len() must be equal to 3"); |
| 322 | } |
| 323 | if n_alpha < 2 || n_theta < 2 { |
| 324 | return Err("n_alpha and n_theta must be ≥ 2"); |
| 325 | } |
| 326 | if k[0] < 0.0 || k[1] < 0.0 || k[2] < 0.0 { |
| 327 | return Err("exponents k must be greater than zero"); |
| 328 | } |
| 329 | let (aa, bb, cc) = (2.0 / k[0], 2.0 / k[1], 2.0 / k[2]); |
| 330 | let a_min = alpha_min * PI / 180.0; |
| 331 | let a_max = alpha_max * PI / 180.0; |
| 332 | let t_min = theta_min * PI / 180.0; |
| 333 | let t_max = theta_max * PI / 180.0; |
| 334 | let d_alpha = (a_max - a_min) / (n_alpha as f64); |
| 335 | let d_theta = (t_max - t_min) / (n_theta as f64); |
| 336 | let mut x = vec![vec![0.0; n_theta + 1]; n_alpha + 1]; |
| 337 | let mut y = vec![vec![0.0; n_theta + 1]; n_alpha + 1]; |
| 338 | let mut z = vec![vec![0.0; n_theta + 1]; n_alpha + 1]; |
| 339 | for i in 0..n_alpha + 1 { |
| 340 | let alpha = a_min + (i as f64) * d_alpha; |
| 341 | for j in 0..n_theta + 1 { |
| 342 | let theta = t_min + (j as f64) * d_theta; |
| 343 | x[i][j] = c[0] + r[0] * suq_cos(theta, aa) * suq_cos(alpha, aa); |
| 344 | y[i][j] = c[1] + r[1] * suq_cos(theta, bb) * suq_sin(alpha, bb); |
| 345 | z[i][j] = c[2] + r[2] * suq_sin(theta, cc); |
| 346 | } |
| 347 | } |
| 348 | self.draw(&x, &y, &z); |
| 349 | Ok((x, y, z)) |
| 350 | } |
| 351 | |
| 352 | /// Draws a sphere |
| 353 | /// |