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

source

pub fn into_scad(self) -> Scad

Turn the Polyhedron into a Scad.

Examples found in repository?
examples/bottle.rs (line 33)
32
33
34
35
36
37
38
39
fn make_cap() {
    let cylinder = Polyhedron::cylinder(23.0, 12.0, 128).into_scad();
    let mut tap = metric_thread::tap(40, 14.0, 128, false, false);
    tap = translate!([0.0, 0.0, 2.0], tap;);

    let cap = cylinder - tap;
    cap.save("output/bottle_cap.scad");
}
More examples
Hide additional 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();
        );
    }
}
source

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");
}
source

pub fn translate(&mut self, point: Pt3)

Translate the polyhedron.

source

pub fn apply_matrix(&mut self, matrix: &Mt4)

Apply the matrix to the polyhedron by multiplying the matrix with each point.

source

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");
}
source

pub fn rotate_y(&mut self, degrees: f64) -> &mut Self

Rotate the polyhedron around the Y axis.

source

pub fn rotate_z(&mut self, degrees: f64) -> &mut Self

Rotate the polyhedron around the Z axis.

source

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.

source

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.

source

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
Hide additional 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");
}
source

pub fn cylinder(radius: f64, height: f64, segments: u64) -> Self

Create a cylinder polyhedron.

Examples found in repository?
examples/bottle.rs (line 33)
32
33
34
35
36
37
38
39
fn make_cap() {
    let cylinder = Polyhedron::cylinder(23.0, 12.0, 128).into_scad();
    let mut tap = metric_thread::tap(40, 14.0, 128, false, false);
    tap = translate!([0.0, 0.0, 2.0], tap;);

    let cap = cylinder - tap;
    cap.save("output/bottle_cap.scad");
}

Trait Implementations§

source§

impl Clone for Polyhedron

source§

fn clone(&self) -> Polyhedron

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.