bottle/
bottle.rs

1// MIT License
2//
3// Copyright (c) 2023 Michael H. Phillips
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23//! This example makes a cap and bottle that can be 3D printed.
24
25use scad_tree::prelude::*;
26
27fn main() {
28    make_bottle();
29    make_cap();
30}
31
32fn make_cap() {
33    let cylinder = Polyhedron::cylinder(23.0, 12.0, 128).into_scad();
34    let mut tap = metric_thread::tap(40, 14.0, 128, false, false);
35    tap = translate!([0.0, 0.0, 2.0], tap;);
36
37    let cap = cylinder - tap;
38    cap.save("output/bottle_cap.scad");
39}
40
41fn make_bottle() {
42    let mut outside_profile = Pt2s::new();
43    outside_profile.push(Pt2::new(0.0, 125.0));
44    outside_profile.append(&mut dim2::cubic_bezier(
45        Pt2::new(19.0, 125.0),
46        Pt2::new(22.5, 110.0),
47        Pt2::new(32.5, 105.0),
48        Pt2::new(32.5, 100.0),
49        6,
50    ));
51    outside_profile.append(&mut dim2::quadratic_bezier(
52        Pt2::new(32.5, 5.0),
53        Pt2::new(32.5, 0.0),
54        Pt2::new(27.5, 0.0),
55        6,
56    ));
57    outside_profile.push(Pt2::new(0.0, 0.0));
58
59    let mut inside_profile = Pt2s::new();
60    inside_profile.push(Pt2::new(0.0, 140.0));
61    inside_profile.push(Pt2::new(16.0, 140.0));
62    inside_profile.append(&mut dim2::cubic_bezier(
63        Pt2::new(16.0, 125.0),
64        Pt2::new(20.5, 110.0),
65        Pt2::new(30.5, 105.0),
66        Pt2::new(30.5, 100.0),
67        6,
68    ));
69    inside_profile.append(&mut dim2::quadratic_bezier(
70        Pt2::new(30.5, 7.0),
71        Pt2::new(30.5, 2.0),
72        Pt2::new(25.5, 2.0),
73        6,
74    ));
75    inside_profile.push(Pt2::new(0.0, 2.0));
76
77    let outside = rotate_extrude!(angle=360.0, convexity=10, fn=128, polygon!(outside_profile););
78    let inside = rotate_extrude!(angle=360.0, convexity=10, fn=128, polygon!(inside_profile););
79
80    let threaded_rod = translate!([0.0,0.0,120.0], metric_thread::threaded_rod(40, 15.0, 128, 0.0, 180.0, false, false););
81
82    let bottle = outside + threaded_rod - inside;
83
84    bottle.save("output/bottle.scad");
85}