pub struct Pt3 {
pub x: f64,
pub y: f64,
pub z: f64,
}
Expand description
A 3D point.
Fields§
§x: f64
§y: f64
§z: f64
Implementations§
Source§impl Pt3
impl Pt3
Sourcepub fn new(x: f64, y: f64, z: f64) -> Pt3
pub fn new(x: f64, y: f64, z: f64) -> Pt3
Examples found in repository?
examples/cup.rs (line 63)
27fn main() {
28 let segments: u64 = 72;
29 let cup_segments: u64 = 144;
30 let slices: u64 = 48;
31
32 let mut cup_blank_profile = Pt2s::new();
33 cup_blank_profile.push(Pt2::new(0.0, 0.0));
34 cup_blank_profile.append(&mut dim2::cubic_bezier(
35 Pt2::new(40.0, 0.0),
36 Pt2::new(40.0, 33.0),
37 Pt2::new(60.0, 66.0),
38 Pt2::new(60.0, 100.0),
39 slices,
40 ));
41 cup_blank_profile.push(Pt2::new(0.0, 100.0));
42
43 let cup_blank = rotate_extrude!(angle=360.0, convexity=2, fn=cup_segments,
44 polygon!(cup_blank_profile);
45 );
46
47 let mut cup_inner_profile = Pt2s::new();
48 cup_inner_profile.push(Pt2::new(0.0, 3.0));
49 cup_inner_profile.append(&mut dim2::cubic_bezier(
50 Pt2::new(37.0, 3.0),
51 Pt2::new(37.0, 33.0),
52 Pt2::new(57.0, 66.0),
53 Pt2::new(57.0, 103.0),
54 slices,
55 ));
56 cup_inner_profile.push(Pt2::new(0.0, 103.0));
57
58 let cup_inner = rotate_extrude!(angle=360.0, convexity=1, fn=cup_segments,
59 polygon!(cup_inner_profile);
60 );
61
62 let handle_path = dim3::cubic_bezier(
63 Pt3::new(37.0, 20.0, 0.0),
64 Pt3::new(70.0, 30.0, 0.0),
65 Pt3::new(120.0, 90.0, 0.0),
66 Pt3::new(57.0, 90.0, 0.0),
67 segments,
68 );
69
70 let handle_profile = dim2::rounded_rect(8.0, 20.0, 2.5, segments, true);
71 let mut handle = Polyhedron::sweep(&handle_profile, &handle_path, 0.0, false);
72 handle.rotate_x(90.0);
73
74 let cup = cup_blank + handle.into_scad_with_convexity(2) - cup_inner;
75
76 cup.save("output/cup.scad");
77}
More examples
examples/scad_tree.rs (line 35)
26fn main() {
27 // The Scad struct and the ScadOp enum are the main types in the library.
28 // This tree is the difference of a cube and a sphere but it's a little
29 // unwieldy to write.
30 Scad {
31 op: ScadOp::Difference,
32 children: vec![
33 Scad {
34 op: ScadOp::Cube {
35 size: Pt3::new(2.0, 2.0, 2.0),
36 center: false,
37 },
38 children: Vec::new(),
39 },
40 Scad {
41 op: ScadOp::Sphere {
42 radius: 1.0,
43 fa: None,
44 fs: None,
45 fn_: Some(24),
46 },
47 children: Vec::new(),
48 },
49 ],
50 }
51 .save("output/scad_tree1.scad");
52
53 // Thats where the macros come in. All the operations from the 2D, 3D, and transformations
54 // sections of the OpenSCAD cheatsheet (https://openscad.org/cheatsheet) are covered by macros.
55 // All of the macros except scad_file expand to a Scad struct literal like above. The scad_file
56 // macro specifies the file to save and allows setting $fa, $fs, and $fn globally.
57
58 // This snippet of macro code produces the tree above but is a bit easier to read and write.
59 // If you squint hard enough it resembles OpenSCAD code!
60 scad_file!(32,
61 "output/scad_tree2.scad",
62 difference!(
63 cube!(2.0);
64 sphere!(1.0, fn=24);
65 );
66 );
67
68 // Maybe your not a fan of OpenSCAD structured code. Since each macro expands to part of a tree
69 // it's easy to save to variables or return a Scad from a funtion. This code produces the same
70 // output as the above.
71 let cube = cube!(2.0);
72 let sphere = sphere!(1.0, fn=24);
73 let difference = difference!(cube; sphere;);
74 difference.save("output/scad_tree3.scad");
75
76 // Maybe you want it to look like math!
77 let cube = cube!(2.0);
78 let sphere = sphere!(1.0, fn=24);
79 (cube - sphere).save("output/scad_tree4.scad");
80}
pub fn dot(self, rhs: Pt3) -> f64
pub fn cross(self, rhs: Pt3) -> Pt3
pub fn len2(self) -> f64
pub fn len(self) -> f64
pub fn normalize(&mut self)
pub fn normalized(self) -> Pt3
pub fn rotated_x(self, degrees: f64) -> Pt3
pub fn rotate_x(&mut self, degrees: f64)
pub fn rotated_y(self, degrees: f64) -> Pt3
pub fn rotate_y(&mut self, degrees: f64)
pub fn rotated_z(self, degrees: f64) -> Pt3
pub fn rotate_z(&mut self, degrees: f64)
pub fn lerp(self, b: Pt3, t: f64) -> Pt3
pub fn as_pt4(self, w: f64) -> Pt4
Trait Implementations§
Source§impl AddAssign for Pt3
impl AddAssign for Pt3
Source§fn add_assign(&mut self, rhs: Pt3)
fn add_assign(&mut self, rhs: Pt3)
Performs the
+=
operation. Read moreSource§impl DivAssign<f64> for Pt3
impl DivAssign<f64> for Pt3
Source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
Performs the
/=
operation. Read moreSource§impl MulAssign<f64> for Pt3
impl MulAssign<f64> for Pt3
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
Performs the
*=
operation. Read moreSource§impl SubAssign for Pt3
impl SubAssign for Pt3
Source§fn sub_assign(&mut self, rhs: Pt3)
fn sub_assign(&mut self, rhs: Pt3)
Performs the
-=
operation. Read moreimpl Copy for Pt3
impl StructuralPartialEq for Pt3
Auto Trait Implementations§
impl Freeze for Pt3
impl RefUnwindSafe for Pt3
impl Send for Pt3
impl Sync for Pt3
impl Unpin for Pt3
impl UnwindSafe for Pt3
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more