Struct scad_tree::dim3::Polyhedron
source · pub struct Polyhedron {
pub points: Pt3s,
pub faces: Faces,
}
Expand description
The points and faces of a polyhedron.
Fields§
§points: Pt3s
§faces: Faces
Implementations§
source§impl Polyhedron
impl Polyhedron
sourcepub fn into_scad(self) -> Scad
pub fn into_scad(self) -> Scad
Turn the Polyhedron into a Scad.
Examples found in repository?
More examples
examples/bezier_star_sweep.rs (line 56)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
fn main() {
let output_viewer = false;
let path = BezierStar::new(7, 20.0, 9.0, 40.0, 15.0, 12);
let profile = BezierStar::new(7, 2.0, 0.9, 4.0, 1.5, 12);
if output_viewer {
let mut viewer = Viewer::new(0.5, 0.25, 6);
viewer.add_bezier_star(&path);
let mut small_viewer = Viewer::new(0.05, 0.025, 6);
small_viewer.add_bezier_star(&profile);
scad_file!("output/bezier_star_sweep.scad",
small_viewer.into_scad() + viewer.into_scad();
);
} else {
let path = Pt3s::from_pt3s(path.gen_points().iter().map(|p| p.as_pt3(0.0)).collect());
let profile = profile.gen_points();
let star_swept = Polyhedron::sweep(&profile, &path, 7.0 * 360.0, true);
scad_file!("output/bezier_star_sweep.scad",
star_swept.into_scad();
);
}
}
sourcepub fn into_scad_with_convexity(self, convexity: u64) -> Scad
pub fn into_scad_with_convexity(self, convexity: u64) -> Scad
Turn the Polyhedron into a Scad with the given convexity.
Examples found in repository?
examples/cup.rs (line 73)
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
fn main() {
let segments: u64 = 36;
let slices: u64 = 12;
let mut cup_blank_profile = Pt2s::new();
cup_blank_profile.push(Pt2::new(0.0, 0.0));
cup_blank_profile.append(&mut dim2::cubic_bezier(
Pt2::new(40.0, 0.0),
Pt2::new(40.0, 33.0),
Pt2::new(60.0, 66.0),
Pt2::new(60.0, 100.0),
slices,
));
cup_blank_profile.push(Pt2::new(0.0, 100.0));
let cup_blank = rotate_extrude!(angle=360.0, convexity=2, fn=segments,
polygon!(cup_blank_profile);
);
let mut cup_inner_profile = Pt2s::new();
cup_inner_profile.push(Pt2::new(0.0, 3.0));
cup_inner_profile.append(&mut dim2::cubic_bezier(
Pt2::new(37.0, 3.0),
Pt2::new(37.0, 33.0),
Pt2::new(57.0, 66.0),
Pt2::new(57.0, 103.0),
slices,
));
cup_inner_profile.push(Pt2::new(0.0, 103.0));
let cup_inner = rotate_extrude!(angle=360.0, convexity=1, fn=segments,
polygon!(cup_inner_profile);
);
let handle_path = dim3::cubic_bezier(
Pt3::new(37.0, 20.0, 0.0),
Pt3::new(70.0, 30.0, 0.0),
Pt3::new(120.0, 90.0, 0.0),
Pt3::new(57.0, 90.0, 0.0),
segments,
);
let handle_profile = dim2::rounded_rect(8.0, 20.0, 2.5, segments, true);
let mut handle = Polyhedron::sweep(&handle_profile, &handle_path, 0.0, false);
handle.rotate_x(90.0);
let cup = cup_blank + handle.into_scad_with_convexity(2) - cup_inner;
cup.save("output/cup.scad");
}
sourcepub fn apply_matrix(&mut self, matrix: &Mt4)
pub fn apply_matrix(&mut self, matrix: &Mt4)
Apply the matrix to the polyhedron by multiplying the matrix with each point.
sourcepub fn rotate_x(&mut self, degrees: f64) -> &mut Self
pub fn rotate_x(&mut self, degrees: f64) -> &mut Self
Rotate the polyhedron around the X axis.
Examples found in repository?
examples/cup.rs (line 71)
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
fn main() {
let segments: u64 = 36;
let slices: u64 = 12;
let mut cup_blank_profile = Pt2s::new();
cup_blank_profile.push(Pt2::new(0.0, 0.0));
cup_blank_profile.append(&mut dim2::cubic_bezier(
Pt2::new(40.0, 0.0),
Pt2::new(40.0, 33.0),
Pt2::new(60.0, 66.0),
Pt2::new(60.0, 100.0),
slices,
));
cup_blank_profile.push(Pt2::new(0.0, 100.0));
let cup_blank = rotate_extrude!(angle=360.0, convexity=2, fn=segments,
polygon!(cup_blank_profile);
);
let mut cup_inner_profile = Pt2s::new();
cup_inner_profile.push(Pt2::new(0.0, 3.0));
cup_inner_profile.append(&mut dim2::cubic_bezier(
Pt2::new(37.0, 3.0),
Pt2::new(37.0, 33.0),
Pt2::new(57.0, 66.0),
Pt2::new(57.0, 103.0),
slices,
));
cup_inner_profile.push(Pt2::new(0.0, 103.0));
let cup_inner = rotate_extrude!(angle=360.0, convexity=1, fn=segments,
polygon!(cup_inner_profile);
);
let handle_path = dim3::cubic_bezier(
Pt3::new(37.0, 20.0, 0.0),
Pt3::new(70.0, 30.0, 0.0),
Pt3::new(120.0, 90.0, 0.0),
Pt3::new(57.0, 90.0, 0.0),
segments,
);
let handle_profile = dim2::rounded_rect(8.0, 20.0, 2.5, segments, true);
let mut handle = Polyhedron::sweep(&handle_profile, &handle_path, 0.0, false);
handle.rotate_x(90.0);
let cup = cup_blank + handle.into_scad_with_convexity(2) - cup_inner;
cup.save("output/cup.scad");
}
sourcepub fn linear_extrude(points: &Pt2s, height: f64) -> Polyhedron
pub fn linear_extrude(points: &Pt2s, height: f64) -> Polyhedron
Extrude a 2D profile into a polyhedron.
Most of the time you want the linear_extrude macro instead of this.
sourcepub fn rotate_extrude(profile: &Pt2s, degrees: f64, segments: usize) -> Self
pub fn rotate_extrude(profile: &Pt2s, degrees: f64, segments: usize) -> Self
Extrude a 2D profile into a polyhedron.
Most of the time you want the rotate_extrude macro instead of this.
sourcepub fn sweep(
profile: &Pt2s,
path: &Pt3s,
twist_degrees: f64,
closed: bool
) -> Self
pub fn sweep( profile: &Pt2s, path: &Pt3s, twist_degrees: f64, closed: bool ) -> Self
Sweeps a 2D profile along a path of 3D points to make a polyhedron.
Examples found in repository?
examples/bezier_star_sweep.rs (line 54)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
fn main() {
let output_viewer = false;
let path = BezierStar::new(7, 20.0, 9.0, 40.0, 15.0, 12);
let profile = BezierStar::new(7, 2.0, 0.9, 4.0, 1.5, 12);
if output_viewer {
let mut viewer = Viewer::new(0.5, 0.25, 6);
viewer.add_bezier_star(&path);
let mut small_viewer = Viewer::new(0.05, 0.025, 6);
small_viewer.add_bezier_star(&profile);
scad_file!("output/bezier_star_sweep.scad",
small_viewer.into_scad() + viewer.into_scad();
);
} else {
let path = Pt3s::from_pt3s(path.gen_points().iter().map(|p| p.as_pt3(0.0)).collect());
let profile = profile.gen_points();
let star_swept = Polyhedron::sweep(&profile, &path, 7.0 * 360.0, true);
scad_file!("output/bezier_star_sweep.scad",
star_swept.into_scad();
);
}
}
More examples
examples/cup.rs (line 70)
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
fn main() {
let segments: u64 = 36;
let slices: u64 = 12;
let mut cup_blank_profile = Pt2s::new();
cup_blank_profile.push(Pt2::new(0.0, 0.0));
cup_blank_profile.append(&mut dim2::cubic_bezier(
Pt2::new(40.0, 0.0),
Pt2::new(40.0, 33.0),
Pt2::new(60.0, 66.0),
Pt2::new(60.0, 100.0),
slices,
));
cup_blank_profile.push(Pt2::new(0.0, 100.0));
let cup_blank = rotate_extrude!(angle=360.0, convexity=2, fn=segments,
polygon!(cup_blank_profile);
);
let mut cup_inner_profile = Pt2s::new();
cup_inner_profile.push(Pt2::new(0.0, 3.0));
cup_inner_profile.append(&mut dim2::cubic_bezier(
Pt2::new(37.0, 3.0),
Pt2::new(37.0, 33.0),
Pt2::new(57.0, 66.0),
Pt2::new(57.0, 103.0),
slices,
));
cup_inner_profile.push(Pt2::new(0.0, 103.0));
let cup_inner = rotate_extrude!(angle=360.0, convexity=1, fn=segments,
polygon!(cup_inner_profile);
);
let handle_path = dim3::cubic_bezier(
Pt3::new(37.0, 20.0, 0.0),
Pt3::new(70.0, 30.0, 0.0),
Pt3::new(120.0, 90.0, 0.0),
Pt3::new(57.0, 90.0, 0.0),
segments,
);
let handle_profile = dim2::rounded_rect(8.0, 20.0, 2.5, segments, true);
let mut handle = Polyhedron::sweep(&handle_profile, &handle_path, 0.0, false);
handle.rotate_x(90.0);
let cup = cup_blank + handle.into_scad_with_convexity(2) - cup_inner;
cup.save("output/cup.scad");
}
Trait Implementations§
source§impl Clone for Polyhedron
impl Clone for Polyhedron
source§fn clone(&self) -> Polyhedron
fn clone(&self) -> Polyhedron
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more