solidruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.travis.yml +3 -0
  4. data/COPYING +674 -0
  5. data/Gemfile +2 -0
  6. data/Guardfile +24 -0
  7. data/LICENSE.md +675 -0
  8. data/README.md +180 -0
  9. data/Rakefile +10 -0
  10. data/bin/solidruby +61 -0
  11. data/examples/chamfered_cube.rb +39 -0
  12. data/examples/filleted_cube.rb +39 -0
  13. data/examples/gear.rb +11 -0
  14. data/examples/knurls.rb +12 -0
  15. data/examples/nut_support.rb +17 -0
  16. data/examples/openscad_examples/old/example001.rb +42 -0
  17. data/examples/openscad_examples/old/example002.rb +45 -0
  18. data/examples/openscad_examples/old/example003.rb +37 -0
  19. data/examples/openscad_examples/old/example004.rb +22 -0
  20. data/examples/openscad_examples/old/example005.rb +45 -0
  21. data/examples/openscad_examples/old/example006.rb +85 -0
  22. data/examples/openscad_examples/old/example007.dxf +2410 -0
  23. data/examples/openscad_examples/old/example007.rb +107 -0
  24. data/examples/openscad_examples/old/example008.rb +61 -0
  25. data/examples/openscad_examples/old/example009.dxf +3894 -0
  26. data/examples/openscad_examples/old/example009.rb.old +48 -0
  27. data/examples/openscad_examples/old/example010.dat +51 -0
  28. data/examples/openscad_examples/old/example010.rb +23 -0
  29. data/examples/openscad_examples/old/example011.rb +42 -0
  30. data/examples/openscad_examples/old/example012.rb +22 -0
  31. data/examples/openscad_examples/old/example012.stl +450 -0
  32. data/examples/openscad_examples/old/example013.dxf +2276 -0
  33. data/examples/openscad_examples/old/example013.rb +30 -0
  34. data/examples/openscad_examples/old/example014.rb +30 -0
  35. data/examples/openscad_examples/old/example015.rb +46 -0
  36. data/examples/openscad_examples/old/example016.rb +75 -0
  37. data/examples/openscad_examples/old/example016.stl +0 -0
  38. data/examples/pipe.rb +38 -0
  39. data/examples/pipe_bug.rb +16 -0
  40. data/examples/printed_gear.rb +12 -0
  41. data/examples/printed_gear2.rb +16 -0
  42. data/examples/printed_thread.rb +9 -0
  43. data/examples/printed_thread2.rb +13 -0
  44. data/examples/stack.rb +21 -0
  45. data/examples/threads.rb +183 -0
  46. data/examples/threads2.rb +93 -0
  47. data/examples/threads3.rb +46 -0
  48. data/lib/solidruby.rb +60 -0
  49. data/lib/solidruby/assemblies/assembly.rb +176 -0
  50. data/lib/solidruby/assemblies/bolt.rb +158 -0
  51. data/lib/solidruby/assemblies/gear.rb +131 -0
  52. data/lib/solidruby/assemblies/linear_bearing.rb +84 -0
  53. data/lib/solidruby/assemblies/nut.rb +153 -0
  54. data/lib/solidruby/assemblies/pipe.rb +153 -0
  55. data/lib/solidruby/assemblies/ruler.rb +44 -0
  56. data/lib/solidruby/assemblies/tslot.rb +141 -0
  57. data/lib/solidruby/assemblies/tslot_machining.rb +62 -0
  58. data/lib/solidruby/assemblies/washer.rb +57 -0
  59. data/lib/solidruby/bill_of_material.rb +43 -0
  60. data/lib/solidruby/csg_modelling/csg_modelling.rb +43 -0
  61. data/lib/solidruby/csg_modelling/difference.rb +41 -0
  62. data/lib/solidruby/csg_modelling/hull.rb +23 -0
  63. data/lib/solidruby/csg_modelling/intersection.rb +24 -0
  64. data/lib/solidruby/csg_modelling/minkowski.rb +23 -0
  65. data/lib/solidruby/csg_modelling/union.rb +41 -0
  66. data/lib/solidruby/csg_modifiers/color.rb +41 -0
  67. data/lib/solidruby/csg_modifiers/csg_modifier.rb +50 -0
  68. data/lib/solidruby/csg_modifiers/linear_extrude.rb +34 -0
  69. data/lib/solidruby/csg_modifiers/projection.rb +29 -0
  70. data/lib/solidruby/csg_modifiers/rotate_extrude.rb +30 -0
  71. data/lib/solidruby/extra.rb +58 -0
  72. data/lib/solidruby/helpers/chamfer.rb +27 -0
  73. data/lib/solidruby/helpers/fillet.rb +28 -0
  74. data/lib/solidruby/helpers/position.rb +267 -0
  75. data/lib/solidruby/helpers/rounded_cube.rb +37 -0
  76. data/lib/solidruby/helpers/triangle.rb +167 -0
  77. data/lib/solidruby/primitives/circle.rb +26 -0
  78. data/lib/solidruby/primitives/cube.rb +123 -0
  79. data/lib/solidruby/primitives/cylinder.rb +72 -0
  80. data/lib/solidruby/primitives/import.rb +42 -0
  81. data/lib/solidruby/primitives/polygon.rb +26 -0
  82. data/lib/solidruby/primitives/polyhedron.rb +30 -0
  83. data/lib/solidruby/primitives/primitive.rb +19 -0
  84. data/lib/solidruby/primitives/render.rb +48 -0
  85. data/lib/solidruby/primitives/sphere.rb +49 -0
  86. data/lib/solidruby/primitives/square.rb +88 -0
  87. data/lib/solidruby/primitives/surface.rb +44 -0
  88. data/lib/solidruby/primitives/text.rb +43 -0
  89. data/lib/solidruby/printed_thread.rb +163 -0
  90. data/lib/solidruby/rubyscad_bridge.rb +376 -0
  91. data/lib/solidruby/screw_thread.rb +170 -0
  92. data/lib/solidruby/solidruby.rb +150 -0
  93. data/lib/solidruby/solidruby_object.rb +176 -0
  94. data/lib/solidruby/transformations/mirror.rb +22 -0
  95. data/lib/solidruby/transformations/rotate.rb +22 -0
  96. data/lib/solidruby/transformations/scale.rb +22 -0
  97. data/lib/solidruby/transformations/transformation.rb +29 -0
  98. data/lib/solidruby/transformations/translate.rb +32 -0
  99. data/lib/solidruby/version.rb +18 -0
  100. data/lib/templates/assembly.tt +13 -0
  101. data/lib/templates/gitignore.tt +3 -0
  102. data/lib/templates/guardfile.tt +4 -0
  103. data/lib/templates/main.tt +20 -0
  104. data/lib/templates/params.tt +3 -0
  105. data/lib/templates/printed.tt +9 -0
  106. data/manual/manual.html +417 -0
  107. data/solidruby.gemspec +35 -0
  108. metadata +277 -0
@@ -0,0 +1,26 @@
1
+ # This file is part of SolidRuby.
2
+ #
3
+ # SolidRuby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # SolidRuby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ module SolidRuby::Primitives
17
+ class Polygon < Primitive
18
+ def to_rubyscad
19
+ RubyScadBridge.new.polygon(@attributes)
20
+ end
21
+ end
22
+
23
+ def polygon(args)
24
+ Polygon.new(args)
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # This file is part of SolidRuby.
2
+ #
3
+ # SolidRuby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # SolidRuby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ module SolidRuby::Primitives
17
+ class Polyhedron < Primitive
18
+ alias_attr :faces
19
+ alias_attr :points
20
+ alias_attr :convexity
21
+
22
+ def to_rubyscad
23
+ RubyScadBridge.new.polyhedron(@attributes)
24
+ end
25
+ end
26
+
27
+ def polyhedron(args)
28
+ Polyhedron.new(args)
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ # This file is part of SolidRuby.
2
+ #
3
+ # SolidRuby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # SolidRuby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ module SolidRuby::Primitives
17
+ class Primitive < SolidRuby::SolidRubyObject
18
+ end
19
+ end
@@ -0,0 +1,48 @@
1
+ # This file is part of SolidRuby.
2
+ #
3
+ # SolidRuby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # SolidRuby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ module SolidRuby::Primitives
17
+ class Render < Primitive
18
+ alias_attr :convexity, :co
19
+
20
+ def initialize(object, attr={})
21
+ @operation = 'render'
22
+ @children = [object]
23
+
24
+ super(attr)
25
+ end
26
+
27
+ def to_rubyscad
28
+ ret = RubyScadBridge.new.render(@attributes) + "{\n"
29
+
30
+ @children ||= []
31
+ @children.each do |child|
32
+ begin
33
+ ret += child.walk_tree
34
+ rescue NoMethodError
35
+ end
36
+ end
37
+ ret += '}'
38
+ end
39
+ end
40
+
41
+ def render(args = {})
42
+ if args.is_a? SolidRubyObject
43
+ Render.new(args)
44
+ else
45
+ Render.new(self, args)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,49 @@
1
+ # This file is part of SolidRuby.
2
+ #
3
+ # SolidRuby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # SolidRuby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ module SolidRuby::Primitives
17
+ class Sphere < Primitive
18
+ alias_attr :d, :diameter
19
+ alias_attr :r, :radius
20
+
21
+ def initialize(args={})
22
+ d = args[:diameter] || args[:d]
23
+ @r = args[:radius] || args[:r] || d/2.0
24
+ super(args)
25
+ end
26
+
27
+ def get_point_on(args = {})
28
+ #approximate a cube the size of this sphere
29
+ args[:x] = @r*Math.sqrt(2)
30
+ args[:y] = @r*Math.sqrt(2)
31
+ args[:z] = @r*Math.sqrt(2)
32
+ args[:centered] = true
33
+ args[:centered_z] = true
34
+ args[:transformations] = @transformations
35
+ calculate_point_on(args)
36
+ end
37
+
38
+ def to_rubyscad
39
+ RubyScadBridge.new.sphere(@attributes)
40
+ end
41
+ end
42
+
43
+ def sphere(args)
44
+ if args.is_a? Numeric
45
+ args = {r: args}
46
+ end
47
+ Sphere.new(args)
48
+ end
49
+ end
@@ -0,0 +1,88 @@
1
+ # This file is part of SolidRuby.
2
+ #
3
+ # SolidRuby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # SolidRuby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ module SolidRuby::Primitives
17
+ class Square < Primitive
18
+ alias_attr :size
19
+
20
+ def initialize(att)
21
+ if att.is_a? Array
22
+ att = { size: att }
23
+ elsif att.is_a? Numeric
24
+ att = { size: att }
25
+ end
26
+
27
+ att[:center] ||= att.delete(:c)
28
+ att.delete(:center) unless att[:center]
29
+
30
+ super(att)
31
+
32
+ unless @attributes[:size]
33
+ x = @attributes.delete(:x) || 0
34
+ y = @attributes.delete(:y) || 0
35
+ @attributes[:size] = [x, y]
36
+ end
37
+ end
38
+
39
+ def x
40
+ if @attributes[:size].is_a? Array
41
+ @attributes[:size][0]
42
+ else
43
+ @attributes[:size]
44
+ end
45
+ end
46
+
47
+ def y
48
+ if @attributes[:size].is_a? Array
49
+ @attributes[:size][1]
50
+ else
51
+ @attributes[:size]
52
+ end
53
+ end
54
+
55
+ def to_rubyscad
56
+ RubyScadBridge.new.square(@attributes)
57
+ end
58
+
59
+ def center_xy
60
+ @attributes[:center] = true
61
+ self
62
+ end
63
+ alias center center_xy
64
+
65
+ def center_x
66
+ @transformations << Translate.new(x: -self.x / 2.0)
67
+ self
68
+ end
69
+
70
+ def center_y
71
+ @transformations << Translate.new(y: -self.y / 2.0)
72
+ self
73
+ end
74
+
75
+ def centered?
76
+ return @attributes[:center] || false
77
+ end
78
+ end
79
+
80
+ def square(args, y = nil)
81
+ if args.is_a?(Numeric) && !!y == y
82
+ args = { size: args, center: y}
83
+ elsif args.is_a?(Numeric) && y.is_a?(Numeric)
84
+ args = { size: [args, y] }
85
+ end
86
+ Square.new(args)
87
+ end
88
+ end
@@ -0,0 +1,44 @@
1
+ # This file is part of SolidRuby.
2
+ #
3
+ # SolidRuby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # SolidRuby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ module SolidRuby::Primitives
17
+ class Surface < Primitive
18
+ alias_attr :file
19
+ alias_attr :invert
20
+ alias_attr :center, :ce
21
+ alias_attr :convexity, :co
22
+
23
+ def initialize(attributes)
24
+ @transformations = []
25
+ @children = []
26
+
27
+ if attributes.is_a? String
28
+ attributes = {file: attributes}
29
+ end
30
+ abs_path = attributes.delete(:absolue_path) || false
31
+
32
+ super(attributes)
33
+ @attributes[:file] = File.expand_path(@attributes[:file]) if abs_path
34
+ end
35
+
36
+ def to_rubyscad
37
+ RubyScadBridge.new.surface(@attributes)
38
+ end
39
+ end
40
+
41
+ def surface(args)
42
+ Surface.new(args)
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ # This file is part of SolidRuby.
2
+ #
3
+ # SolidRuby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # SolidRuby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ module SolidRuby::Primitives
17
+ class Text < Primitive
18
+ alias_attr :text
19
+ alias_attr :size
20
+ alias_attr :font
21
+ alias_attr :valign, :va
22
+ alias_attr :halign, :ha
23
+ alias_attr :spacing, :sp
24
+ alias_attr :direction
25
+ alias_attr :language
26
+ alias_attr :script, :sc
27
+
28
+ def initialize(attributes)
29
+ if attributes.is_a? String
30
+ attributes = {text: attributes}
31
+ end
32
+ super(attributes)
33
+ end
34
+
35
+ def to_rubyscad
36
+ RubyScadBridge.new.text(@attributes)
37
+ end
38
+ end
39
+
40
+ def text(args = {})
41
+ Text.new(args)
42
+ end
43
+ end
@@ -0,0 +1,163 @@
1
+ # This file is part of SolidRuby.
2
+ #
3
+ # SolidRuby is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # SolidRuby is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with SolidRuby. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ module SolidRuby::PrintedThreads
17
+ # Ported from
18
+ # http://dkprojects.net/openscad-threads/threads.scad
19
+ #
20
+ # original Author Dan Kirshner - dan_kirshner@yahoo.com
21
+
22
+ class PrintedThread
23
+ # internal - true = clearances for internal thread (e.g., a nut).
24
+ # false = clearances for external thread (e.g., a bolt).
25
+ # (Internal threads should be "cut out" from a solid using
26
+ # difference()).
27
+ # number_of_starts - Number of thread starts (e.g., DNA, a "double helix," has
28
+ # n_starts=2). See wikipedia Screw_thread.
29
+ def initialize(args = {})
30
+ @args = args
31
+ @args[:diameter] ||= 8
32
+ @args[:pitch] ||= 1.25
33
+ @args[:length] ||= 10
34
+ @args[:internal] ||= false
35
+ @args[:number_of_starts] ||= 1
36
+ end
37
+
38
+ def show
39
+ output
40
+ end
41
+
42
+ def output
43
+ number_of_turns = (@args[:length].to_f / @args[:pitch].to_f).floor
44
+ number_of_segments = segments(@args[:diameter])
45
+ h = @args[:pitch] * Math.cos(radians(30))
46
+
47
+ res = nil
48
+ ((-1 * @args[:number_of_starts])..(number_of_turns + 1)).each do |i|
49
+ res += metric_thread_turn(@args[:diameter], @args[:pitch], @args[:internal], @args[:number_of_starts]).translate(z: i * @args[:pitch])
50
+ end
51
+ # cut to length
52
+ res *= cube(x: @args[:diameter] * 1.1, y: @args[:diameter] * 1.1, z: @args[:length]).center.translate(z: @args[:length] / 2.0)
53
+
54
+ if @args[:internal]
55
+ # Solid center, including Dmin truncation.
56
+ res += cylinder(r: @args[:diameter] / 2.0 - h * 5.0 / 8.0, h: @args[:length], segments: number_of_segments)
57
+ else
58
+ # External thread includes additional relief.
59
+ res += cylinder(r: @args[:diameter] / 2.0 - h * 5.3 / 8.0, h: @args[:length], segments: number_of_segments)
60
+ end
61
+
62
+ res
63
+ end
64
+
65
+ def segments(diameter)
66
+ [50, (diameter * 6).ceil].min
67
+ end
68
+
69
+ def metric_thread_turn(diameter, pitch, internal, number_of_starts)
70
+ number_of_segments = segments(diameter)
71
+ fraction_circle = 1.0 / number_of_segments
72
+ res = nil
73
+
74
+ (0..number_of_segments - 1).each do |i|
75
+ res += thread_polyhedron(diameter / 2.0, pitch, internal, number_of_starts).translate(z: i * number_of_starts * pitch * fraction_circle).rotate(z: i * 360 * fraction_circle)
76
+ end
77
+ res
78
+ end
79
+
80
+ # z (see diagram) as function of current radius.
81
+ # (Only good for first half-pitch.)
82
+ def z_fct(current_radius, radius, pitch)
83
+ 0.5 * (current_radius - (radius - 0.875 * pitch * Math.cos(radians(30)))) / Math.cos(radians(30))
84
+ end
85
+
86
+ #
87
+ # (angles x0 and x3 inner are actually 60 deg)
88
+ #
89
+ # /\ (x2_inner, z2_inner) [2]
90
+ # / \
91
+ # (x3_inner, z3_inner) / \
92
+ # [3] \ \
93
+ # |\ \ (x2_outer, z2_outer) [6]
94
+ # | \ /
95
+ # | \ /|
96
+ # z | \/ / (x1_outer, z1_outer) [5]
97
+ # | | | /
98
+ # | x | |/
99
+ # | / | / (x0_outer, z0_outer) [4]
100
+ # | / | / (behind: (x1_inner, z1_inner) [1]
101
+ # |/ | /
102
+ # y________| |/
103
+ # (r) / (x0_inner, z0_inner) [0]
104
+ #
105
+ #
106
+ def thread_polyhedron(radius, pitch, internal, n_starts)
107
+ n_segments = segments(radius * 2)
108
+ fraction_circle = 1.0 / n_segments
109
+
110
+ h = pitch * Math.cos(radians(30))
111
+ outer_r = radius + (internal ? h / 20 : 0) # Adds internal relief.
112
+
113
+ inner_r = radius - 0.875 * h # Does NOT do Dmin_truncation - do later with cylinder.
114
+
115
+ # Make these just slightly bigger (keep in proportion) so polyhedra will overlap.
116
+ x_incr_outer = outer_r * fraction_circle * 2 * Math::PI * 1.005
117
+ x_incr_inner = inner_r * fraction_circle * 2 * Math::PI * 1.005
118
+ z_incr = n_starts * pitch * fraction_circle * 1.005
119
+
120
+ #TODO: test code to see if x1_outer and/or z1_outer are needed
121
+ #x1_outer = outer_r * fraction_circle * 2 * Math::PI
122
+
123
+ z0_outer = z_fct(outer_r, radius, pitch)
124
+ #z1_outer = z0_outer + z_incr
125
+ # Rule for triangle ordering: look at polyhedron from outside: points must
126
+ # be in clockwise order.
127
+
128
+ points = [
129
+ [-x_incr_inner / 2, -inner_r, 0], # [0]
130
+ [x_incr_inner / 2, -inner_r, z_incr], # [1]
131
+ [x_incr_inner / 2, -inner_r, pitch + z_incr], # [2]
132
+ [-x_incr_inner / 2, -inner_r, pitch], # [3]
133
+
134
+ [-x_incr_outer / 2, -outer_r, z0_outer], # [4]
135
+ [x_incr_outer / 2, -outer_r, z0_outer + z_incr], # [5]
136
+ [x_incr_outer / 2, -outer_r, pitch - z0_outer + z_incr], # [6]
137
+ [-x_incr_outer / 2, -outer_r, pitch - z0_outer] # [7]
138
+ ]
139
+
140
+ triangles = [
141
+ [0, 3, 4], # This-side trapezoid, bottom
142
+ [3, 7, 4], # This-side trapezoid, top
143
+
144
+ [1, 5, 2], # Back-side trapezoid, bottom
145
+ [2, 5, 6], # Back-side trapezoid, top
146
+
147
+ [0, 1, 2], # Inner rectangle, bottom
148
+ [0, 2, 3], # Inner rectangle, top
149
+
150
+ [4, 6, 5], # Outer rectangle, bottom
151
+ [4, 7, 6], # Outer rectangle, top
152
+
153
+ [7, 2, 6], # Upper rectangle, bottom
154
+ [7, 3, 2], # Upper rectangle, top
155
+
156
+ [0, 5, 1], # Lower rectangle, bottom
157
+ [0, 4, 5] # Lower rectangle, top
158
+ ]
159
+
160
+ polyhedron(points: points, triangles: triangles)
161
+ end
162
+ end
163
+ end