MCPcopy Create free account
hub / github.com/cpmech/plotpy / draw_hemisphere

Method draw_hemisphere

src/surface_geometry.rs:216–256  ·  view source on GitHub ↗

Draws a hemisphere # Input `c` -- (len=3) center coordinates `r` -- radius `alpha_min` -- min α angle in [-180, 180) degrees `alpha_max` -- max α angle in (-180, 180] degrees `n_alpha` -- number of divisions along α (must be ≥ 2) `n_theta` -- number of divisions along θ (must be ≥ 2) `cup` -- upside-down; like a cup # Output `x`, `y`, `z` -- the coordinates of all points as in a meshgrid # Ex

(
        &mut self,
        c: &[f64],
        r: f64,
        alpha_min: f64,
        alpha_max: f64,
        n_alpha: usize,
        n_theta: usize,
        cup: bool,
    )

Source from the content-addressed store, hash-verified

214 /// See also integration test in the **tests** directory.
215 ///
216 pub fn draw_hemisphere(
217 &mut self,
218 c: &[f64],
219 r: f64,
220 alpha_min: f64,
221 alpha_max: f64,
222 n_alpha: usize,
223 n_theta: usize,
224 cup: bool,
225 ) -> Result<(Vec<Vec<f64>>, Vec<Vec<f64>>, Vec<Vec<f64>>), StrError> {
226 if c.len() != 3 {
227 return Err("c.len() must be equal to 3");
228 }
229 if n_alpha < 2 || n_theta < 2 {
230 return Err("n_alpha and n_theta must be ≥ 2");
231 }
232 let a_min = alpha_min * PI / 180.0;
233 let a_max = alpha_max * PI / 180.0;
234 let d_alpha = (a_max - a_min) / (n_alpha as f64);
235 let d_theta = (PI / 2.0) / (n_theta as f64);
236 let mut x = vec![vec![0.0; n_theta + 1]; n_alpha + 1];
237 let mut y = vec![vec![0.0; n_theta + 1]; n_alpha + 1];
238 let mut z = vec![vec![0.0; n_theta + 1]; n_alpha + 1];
239 for i in 0..n_alpha + 1 {
240 let alpha = a_min + (i as f64) * d_alpha;
241 for j in 0..n_theta + 1 {
242 let theta = (j as f64) * d_theta;
243 if cup {
244 x[i][j] = c[0] + r * f64::cos(alpha) * f64::sin(theta);
245 y[i][j] = c[1] + r * f64::sin(alpha) * f64::sin(theta);
246 z[i][j] = c[2] - r * f64::cos(theta);
247 } else {
248 x[i][j] = c[0] + r * f64::cos(alpha) * f64::sin(theta);
249 y[i][j] = c[1] + r * f64::sin(alpha) * f64::sin(theta);
250 z[i][j] = c[2] + r * f64::cos(theta);
251 }
252 }
253 }
254 self.draw(&x, &y, &z);
255 Ok((x, y, z))
256 }
257
258 /// Draws a superquadric (includes sphere, super-ellipsoid, and super-hyperboloid)
259 ///

Callers 3

draw_hemisphere_worksFunction · 0.80
test_surface_geometryFunction · 0.80

Calls 1

drawMethod · 0.45

Tested by 3

draw_hemisphere_worksFunction · 0.64
test_surface_geometryFunction · 0.64