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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +3 -0
- data/COPYING +674 -0
- data/Gemfile +2 -0
- data/Guardfile +24 -0
- data/LICENSE.md +675 -0
- data/README.md +180 -0
- data/Rakefile +10 -0
- data/bin/solidruby +61 -0
- data/examples/chamfered_cube.rb +39 -0
- data/examples/filleted_cube.rb +39 -0
- data/examples/gear.rb +11 -0
- data/examples/knurls.rb +12 -0
- data/examples/nut_support.rb +17 -0
- data/examples/openscad_examples/old/example001.rb +42 -0
- data/examples/openscad_examples/old/example002.rb +45 -0
- data/examples/openscad_examples/old/example003.rb +37 -0
- data/examples/openscad_examples/old/example004.rb +22 -0
- data/examples/openscad_examples/old/example005.rb +45 -0
- data/examples/openscad_examples/old/example006.rb +85 -0
- data/examples/openscad_examples/old/example007.dxf +2410 -0
- data/examples/openscad_examples/old/example007.rb +107 -0
- data/examples/openscad_examples/old/example008.rb +61 -0
- data/examples/openscad_examples/old/example009.dxf +3894 -0
- data/examples/openscad_examples/old/example009.rb.old +48 -0
- data/examples/openscad_examples/old/example010.dat +51 -0
- data/examples/openscad_examples/old/example010.rb +23 -0
- data/examples/openscad_examples/old/example011.rb +42 -0
- data/examples/openscad_examples/old/example012.rb +22 -0
- data/examples/openscad_examples/old/example012.stl +450 -0
- data/examples/openscad_examples/old/example013.dxf +2276 -0
- data/examples/openscad_examples/old/example013.rb +30 -0
- data/examples/openscad_examples/old/example014.rb +30 -0
- data/examples/openscad_examples/old/example015.rb +46 -0
- data/examples/openscad_examples/old/example016.rb +75 -0
- data/examples/openscad_examples/old/example016.stl +0 -0
- data/examples/pipe.rb +38 -0
- data/examples/pipe_bug.rb +16 -0
- data/examples/printed_gear.rb +12 -0
- data/examples/printed_gear2.rb +16 -0
- data/examples/printed_thread.rb +9 -0
- data/examples/printed_thread2.rb +13 -0
- data/examples/stack.rb +21 -0
- data/examples/threads.rb +183 -0
- data/examples/threads2.rb +93 -0
- data/examples/threads3.rb +46 -0
- data/lib/solidruby.rb +60 -0
- data/lib/solidruby/assemblies/assembly.rb +176 -0
- data/lib/solidruby/assemblies/bolt.rb +158 -0
- data/lib/solidruby/assemblies/gear.rb +131 -0
- data/lib/solidruby/assemblies/linear_bearing.rb +84 -0
- data/lib/solidruby/assemblies/nut.rb +153 -0
- data/lib/solidruby/assemblies/pipe.rb +153 -0
- data/lib/solidruby/assemblies/ruler.rb +44 -0
- data/lib/solidruby/assemblies/tslot.rb +141 -0
- data/lib/solidruby/assemblies/tslot_machining.rb +62 -0
- data/lib/solidruby/assemblies/washer.rb +57 -0
- data/lib/solidruby/bill_of_material.rb +43 -0
- data/lib/solidruby/csg_modelling/csg_modelling.rb +43 -0
- data/lib/solidruby/csg_modelling/difference.rb +41 -0
- data/lib/solidruby/csg_modelling/hull.rb +23 -0
- data/lib/solidruby/csg_modelling/intersection.rb +24 -0
- data/lib/solidruby/csg_modelling/minkowski.rb +23 -0
- data/lib/solidruby/csg_modelling/union.rb +41 -0
- data/lib/solidruby/csg_modifiers/color.rb +41 -0
- data/lib/solidruby/csg_modifiers/csg_modifier.rb +50 -0
- data/lib/solidruby/csg_modifiers/linear_extrude.rb +34 -0
- data/lib/solidruby/csg_modifiers/projection.rb +29 -0
- data/lib/solidruby/csg_modifiers/rotate_extrude.rb +30 -0
- data/lib/solidruby/extra.rb +58 -0
- data/lib/solidruby/helpers/chamfer.rb +27 -0
- data/lib/solidruby/helpers/fillet.rb +28 -0
- data/lib/solidruby/helpers/position.rb +267 -0
- data/lib/solidruby/helpers/rounded_cube.rb +37 -0
- data/lib/solidruby/helpers/triangle.rb +167 -0
- data/lib/solidruby/primitives/circle.rb +26 -0
- data/lib/solidruby/primitives/cube.rb +123 -0
- data/lib/solidruby/primitives/cylinder.rb +72 -0
- data/lib/solidruby/primitives/import.rb +42 -0
- data/lib/solidruby/primitives/polygon.rb +26 -0
- data/lib/solidruby/primitives/polyhedron.rb +30 -0
- data/lib/solidruby/primitives/primitive.rb +19 -0
- data/lib/solidruby/primitives/render.rb +48 -0
- data/lib/solidruby/primitives/sphere.rb +49 -0
- data/lib/solidruby/primitives/square.rb +88 -0
- data/lib/solidruby/primitives/surface.rb +44 -0
- data/lib/solidruby/primitives/text.rb +43 -0
- data/lib/solidruby/printed_thread.rb +163 -0
- data/lib/solidruby/rubyscad_bridge.rb +376 -0
- data/lib/solidruby/screw_thread.rb +170 -0
- data/lib/solidruby/solidruby.rb +150 -0
- data/lib/solidruby/solidruby_object.rb +176 -0
- data/lib/solidruby/transformations/mirror.rb +22 -0
- data/lib/solidruby/transformations/rotate.rb +22 -0
- data/lib/solidruby/transformations/scale.rb +22 -0
- data/lib/solidruby/transformations/transformation.rb +29 -0
- data/lib/solidruby/transformations/translate.rb +32 -0
- data/lib/solidruby/version.rb +18 -0
- data/lib/templates/assembly.tt +13 -0
- data/lib/templates/gitignore.tt +3 -0
- data/lib/templates/guardfile.tt +4 -0
- data/lib/templates/main.tt +20 -0
- data/lib/templates/params.tt +3 -0
- data/lib/templates/printed.tt +9 -0
- data/manual/manual.html +417 -0
- data/solidruby.gemspec +35 -0
- metadata +277 -0
|
@@ -0,0 +1,37 @@
|
|
|
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::Helpers
|
|
17
|
+
def rounded_cube(args = {}, y = nil, z = nil)
|
|
18
|
+
c = cube(args, y, z)
|
|
19
|
+
r = args[:r]
|
|
20
|
+
sx = c.x - r * 2
|
|
21
|
+
sy = c.y - r * 2
|
|
22
|
+
sz = c.z - r
|
|
23
|
+
|
|
24
|
+
res = hull(
|
|
25
|
+
sphere(r: r).translate(z: r),
|
|
26
|
+
sphere(r: r).translate(z: sz),
|
|
27
|
+
sphere(r: r).translate(x: sx, z: sz),
|
|
28
|
+
sphere(r: r).translate(x: sx, y: sy, z: sz),
|
|
29
|
+
sphere(r: r).translate(y: sy, z: sz),
|
|
30
|
+
sphere(r: r).translate(x: sx, z: r),
|
|
31
|
+
sphere(r: r).translate(y: sy, z: r),
|
|
32
|
+
sphere(r: r).translate(x: sx, y: sy, z: r)
|
|
33
|
+
).translate(x: r, y: r)
|
|
34
|
+
|
|
35
|
+
res
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,167 @@
|
|
|
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::Helpers
|
|
17
|
+
#Helper class for creating triangles, given three inputs
|
|
18
|
+
# (at least 1 side + angles)
|
|
19
|
+
#The triangle can then either be used as a Polygon,
|
|
20
|
+
#or it can be thrown away and used just for calcuation of the triangle
|
|
21
|
+
#order is assumed as follows:
|
|
22
|
+
# @a is opposite @alpha, @b is opposite @beta, @c is opposite @gamma
|
|
23
|
+
# Angles go clockwise with @alpha at the origin
|
|
24
|
+
# Sides go clockwise with @a along the X axis, and @c along Y
|
|
25
|
+
class Triangle < SolidRuby::Primitives::Polygon
|
|
26
|
+
attr_accessor :alpha, :beta, :gamma, :a, :b, :c, :has_alt_solution
|
|
27
|
+
def initialize(args = {})
|
|
28
|
+
use_alt_solution = args[:alt_solution] || false
|
|
29
|
+
|
|
30
|
+
if args.reject{|k| k == :alt_solution}.count != 3
|
|
31
|
+
raise "Triangle requires exactly 3 inputs"
|
|
32
|
+
elsif args[:a].nil? && args[:b].nil? && args[:c].nil?
|
|
33
|
+
raise "Triangle requires at least 1 side length"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#try to solve twice to see if we have two solutions
|
|
37
|
+
sol_count = 0
|
|
38
|
+
solution = solve(args, false)
|
|
39
|
+
sol_count += 1 unless solution.nil?
|
|
40
|
+
solution_alt = solve(args, true)
|
|
41
|
+
sol_count += 1 unless solution_alt.nil?
|
|
42
|
+
|
|
43
|
+
raise "Could not solve triangle." if sol_count == 0
|
|
44
|
+
|
|
45
|
+
@has_alt_solution = sol_count == 2 ? true : false
|
|
46
|
+
|
|
47
|
+
if use_alt_solution
|
|
48
|
+
update(solution_alt)
|
|
49
|
+
else
|
|
50
|
+
update(solution)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#consturct triangle polygon
|
|
54
|
+
args = {points: [
|
|
55
|
+
[0.0, 0.0],
|
|
56
|
+
[@b, 0.0],
|
|
57
|
+
[@c * Math.cos(radians(@alpha)), height(:beta)],
|
|
58
|
+
[0.0, 0.0]]}
|
|
59
|
+
|
|
60
|
+
super(args)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def height(angle)
|
|
64
|
+
case angle
|
|
65
|
+
when :alpha
|
|
66
|
+
ang = @beta
|
|
67
|
+
side = @c
|
|
68
|
+
when :beta
|
|
69
|
+
ang = @alpha
|
|
70
|
+
side = @c
|
|
71
|
+
else
|
|
72
|
+
ang = @alpha
|
|
73
|
+
side = @b
|
|
74
|
+
end
|
|
75
|
+
Math.sin(radians(ang)) * side.to_f
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
def update(params)
|
|
80
|
+
@alpha = params[:alpha]
|
|
81
|
+
@beta = params[:beta]
|
|
82
|
+
@gamma = params[:gamma]
|
|
83
|
+
@a = params[:a]
|
|
84
|
+
@b = params[:b]
|
|
85
|
+
@c = params[:c]
|
|
86
|
+
end
|
|
87
|
+
#Solve for any missing angles/sides
|
|
88
|
+
def solve(triangle_params, alt_solution)
|
|
89
|
+
alpha = triangle_params[:alpha]
|
|
90
|
+
beta = triangle_params[:beta]
|
|
91
|
+
gamma = triangle_params[:gamma]
|
|
92
|
+
a = triangle_params[:a]
|
|
93
|
+
b = triangle_params[:b]
|
|
94
|
+
c = triangle_params[:c]
|
|
95
|
+
|
|
96
|
+
#find side for SAS case
|
|
97
|
+
a = solve_side_from_single_angle(b, c, alpha) if a.nil?
|
|
98
|
+
b = solve_side_from_single_angle(a, c, beta) if b.nil?
|
|
99
|
+
c = solve_side_from_single_angle(a, b, gamma) if c.nil?
|
|
100
|
+
|
|
101
|
+
#find one angle (SSS case)
|
|
102
|
+
alpha = solve_angle_from_sides(b, c, a) if alpha.nil?
|
|
103
|
+
beta = solve_angle_from_sides(a, c, b) if beta.nil?
|
|
104
|
+
gamma = solve_angle_from_sides(a, b, c) if gamma.nil?
|
|
105
|
+
|
|
106
|
+
#now we know at least one angle, find the next one (SSA case)
|
|
107
|
+
alpha = solve_angle_from_angle(a, b, beta, alt_solution) if alpha.nil?
|
|
108
|
+
alpha = solve_angle_from_angle(a, c, gamma, alt_solution) if alpha.nil?
|
|
109
|
+
beta = solve_angle_from_angle(b, a, alpha, alt_solution) if beta.nil?
|
|
110
|
+
beta = solve_angle_from_angle(b, c, gamma, alt_solution) if beta.nil?
|
|
111
|
+
gamma = solve_angle_from_angle(c, a, alpha, alt_solution) if gamma.nil?
|
|
112
|
+
gamma = solve_angle_from_angle(c, b, beta, alt_solution) if gamma.nil?
|
|
113
|
+
|
|
114
|
+
#now we know at least two angles, solve the third one
|
|
115
|
+
alpha = sub_angles(beta, gamma) if alpha.nil?
|
|
116
|
+
beta = sub_angles(alpha, gamma) if beta.nil?
|
|
117
|
+
gamma = sub_angles(alpha, beta) if gamma.nil?
|
|
118
|
+
|
|
119
|
+
#we know all the angles, now find any unknown sides
|
|
120
|
+
a = solve_side(alpha, b, beta) if a.nil?
|
|
121
|
+
a = solve_side(alpha, c, gamma) if a.nil?
|
|
122
|
+
b = solve_side(beta, a, alpha) if b.nil?
|
|
123
|
+
b = solve_side(beta, c, gamma) if b.nil?
|
|
124
|
+
c = solve_side(gamma, a, alpha) if c.nil?
|
|
125
|
+
c = solve_side(gamma, b, beta) if c.nil?
|
|
126
|
+
|
|
127
|
+
return nil if a.nil? || b.nil? || c.nil? || alpha.nil? || beta.nil? || gamma.nil?
|
|
128
|
+
{a: a, b: b, c: c, alpha: alpha, beta: beta, gamma: gamma}
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def sub_angles(angle1, angle2)
|
|
132
|
+
return nil if angle1.nil? || angle2.nil?
|
|
133
|
+
180 - angle1 - angle2
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def solve_angle_from_sides(adj_side, adj_side2, opp_side)
|
|
137
|
+
return nil if adj_side.nil? || adj_side2.nil? || opp_side.nil? ||
|
|
138
|
+
adj_side == 0 || adj_side2 == 0 || opp_side == 0
|
|
139
|
+
|
|
140
|
+
degrees(Math.acos((adj_side**2 + adj_side2**2 - opp_side**2) / (2.0 * adj_side * adj_side2)))
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def solve_angle_from_angle(opp_side, adj_side, adj_angle, alt_solution)
|
|
144
|
+
return nil if opp_side.nil? || adj_side.nil? || adj_angle.nil?
|
|
145
|
+
|
|
146
|
+
res = degrees(Math.asin(opp_side * Math.sin(radians(adj_angle)) / adj_side))
|
|
147
|
+
res = 180 - res if alt_solution
|
|
148
|
+
res
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def solve_side_from_single_angle(side1, side2, angle)
|
|
152
|
+
return nil if side1.nil? || side2.nil? || angle.nil?
|
|
153
|
+
|
|
154
|
+
Math.sqrt(side1**2 + side2**2 - 2 * side1 * side2 * Math.cos(radians(angle)))
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def solve_side(opp_angle, adj_side, adj_opp_angle)
|
|
158
|
+
return nil if opp_angle.nil? || adj_side.nil? || adj_opp_angle.nil?
|
|
159
|
+
|
|
160
|
+
(Math.sin(radians(opp_angle)) * adj_side)/Math.sin(radians(adj_opp_angle))
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def triangle(args)
|
|
165
|
+
Triangle.new(args)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -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 Circle < Primitive
|
|
18
|
+
def to_rubyscad
|
|
19
|
+
RubyScadBridge.new.circle(@attributes)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def circle(args)
|
|
24
|
+
Circle.new(args)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
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 Cube < Primitive
|
|
18
|
+
attr_accessor :x, :y, :z
|
|
19
|
+
|
|
20
|
+
def initialize(args={}, y = nil, z = nil)
|
|
21
|
+
if args.is_a? Array
|
|
22
|
+
args = { x: args[0], y: args[1], z: args[2] }
|
|
23
|
+
elsif args.is_a?(Hash) && args[:size]
|
|
24
|
+
args[:x] ||= args[:size][0] || 0
|
|
25
|
+
args[:y] ||= args[:size][1] || 0
|
|
26
|
+
args[:z] ||= args[:size][2] || 0
|
|
27
|
+
elsif args.is_a? Numeric
|
|
28
|
+
x = args
|
|
29
|
+
y ||= x
|
|
30
|
+
z ||= y# = x if y.nil? && z.nil?
|
|
31
|
+
args = { x: x, y: y, z: z }
|
|
32
|
+
end
|
|
33
|
+
@centered = args.delete(:center) || args.delete(:c)
|
|
34
|
+
|
|
35
|
+
@x = args[:x]
|
|
36
|
+
@y = args[:y] || @x
|
|
37
|
+
@z = args[:z] || @y
|
|
38
|
+
super(args)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def center_xy
|
|
42
|
+
@transformations << Translate.new(x: -@x / 2.0, y: -@y / 2.0)
|
|
43
|
+
self
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def center_x
|
|
47
|
+
@transformations << Translate.new(x: -@x / 2.0)
|
|
48
|
+
self
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def center_y
|
|
52
|
+
@transformations << Translate.new(y: -@y / 2.0)
|
|
53
|
+
self
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def center_z
|
|
57
|
+
@transformations << Translate.new(z: -@z / 2.0)
|
|
58
|
+
self
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def center
|
|
62
|
+
@centered = true
|
|
63
|
+
self
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def centered?
|
|
67
|
+
@centered
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def chamfer(args = {})
|
|
71
|
+
faces = normalise_edges(args)
|
|
72
|
+
height = args[:h] || args[:height]
|
|
73
|
+
trans = translations_for_edge(onto: self, faces: faces, x: @x, y: @y, z: @z)
|
|
74
|
+
res = self
|
|
75
|
+
trans.each do |t|
|
|
76
|
+
res -= Helpers::chamfer(l: t[:length] + 0.02, h: height)
|
|
77
|
+
.rotate(z: (t[:z_rot] - 180))
|
|
78
|
+
.rotate(x: t[:x_rot], y: t[:y_rot])
|
|
79
|
+
.translate(x: t[:x_trans], y: t[:y_trans], z: t[:z_trans])
|
|
80
|
+
end
|
|
81
|
+
res
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def get_point_on(args = {})
|
|
85
|
+
args[:x] = @x
|
|
86
|
+
args[:y] = @y
|
|
87
|
+
args[:z] = @z
|
|
88
|
+
args[:centered] = @centered
|
|
89
|
+
args[:centered_z] = @centered
|
|
90
|
+
args[:transformations] = @transformations
|
|
91
|
+
calculate_point_on(args)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def fillet(args = {})
|
|
95
|
+
faces = normalise_edges(args)
|
|
96
|
+
radius = args[:r] || args[:radiusg]
|
|
97
|
+
trans = translations_for_edge(onto: self, faces: faces, x: @x, y: @y, z: @z, tolerance: 0)
|
|
98
|
+
res = self
|
|
99
|
+
trans.each do |t|
|
|
100
|
+
res -= Helpers::fillet(h: t[:length], r: radius)
|
|
101
|
+
.rotate(z: t[:z_rot])
|
|
102
|
+
.rotate(x: t[:x_rot], y: t[:y_rot])
|
|
103
|
+
.translate(x: t[:x_trans], y: t[:y_trans], z: t[:z_trans])
|
|
104
|
+
end
|
|
105
|
+
res
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def to_rubyscad
|
|
109
|
+
args = { size: [@x, @y, @z] }
|
|
110
|
+
args[:center] = @centered if @centered
|
|
111
|
+
RubyScadBridge.new.cube(args)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def cube(args = {}, y = nil, z = nil)
|
|
116
|
+
if args.is_a? Numeric
|
|
117
|
+
args = {x: args}
|
|
118
|
+
args[:y] = y if y
|
|
119
|
+
args[:z] = z if z
|
|
120
|
+
end
|
|
121
|
+
Cube.new(args)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
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 Cylinder < Primitive
|
|
18
|
+
alias_attr :h, :height
|
|
19
|
+
alias_attr :r, :radius
|
|
20
|
+
|
|
21
|
+
def initialize(args={})
|
|
22
|
+
d = args[:diameter] || args[:d]
|
|
23
|
+
d /= 2.0 unless d.nil?
|
|
24
|
+
@r = args[:radius] || args[:r] || d
|
|
25
|
+
@h = args[:height] || args[:h]
|
|
26
|
+
super(args)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_rubyscad
|
|
30
|
+
RubyScadBridge.new.cylinder(@attributes)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def get_point_on(args = {})
|
|
34
|
+
# a cube the same size as the cylinder
|
|
35
|
+
args[:x] = @r*Math.sqrt(2)
|
|
36
|
+
args[:y] = @r*Math.sqrt(2)
|
|
37
|
+
args[:z] = @h
|
|
38
|
+
args[:centered] = true
|
|
39
|
+
args[:centered_z] = false
|
|
40
|
+
args[:transformations] = @transformations
|
|
41
|
+
calculate_point_on(args)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def cylinder(args)
|
|
46
|
+
# inner diameter handling
|
|
47
|
+
if args[:id]
|
|
48
|
+
id = args.delete(:id)
|
|
49
|
+
args2 = args.dup
|
|
50
|
+
args2[:d] = id
|
|
51
|
+
|
|
52
|
+
if args[:ih]
|
|
53
|
+
# if it has an inner height, add a tiny bit to the bottom
|
|
54
|
+
ih = args.delete(:ih)
|
|
55
|
+
args2[:h] = ih + 0.01
|
|
56
|
+
else
|
|
57
|
+
# otherwise add to both bottom and top to make a clear cut in OpenSCAD
|
|
58
|
+
args2[:h] += 0.02
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# if we have a ifn value, change the fn value of the inner cut
|
|
62
|
+
if args[:ifn]
|
|
63
|
+
ifn = args.delete(:ifn)
|
|
64
|
+
args2[:fn] = ifn
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
return cylinder(args) - cylinder(args2).translate(z: -0.01)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
Cylinder.new(args)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
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 Import < Primitive
|
|
18
|
+
alias_attr :file
|
|
19
|
+
alias_attr :layer
|
|
20
|
+
alias_attr :center, :ce
|
|
21
|
+
alias_attr :convexity, :co
|
|
22
|
+
alias_attr :scale
|
|
23
|
+
|
|
24
|
+
def initialize(attributes)
|
|
25
|
+
if attributes.is_a? String
|
|
26
|
+
attributes = {file: attributes}
|
|
27
|
+
end
|
|
28
|
+
abs_path = attributes.delete(:absolue_path) || false
|
|
29
|
+
|
|
30
|
+
super(attributes)
|
|
31
|
+
@attributes[:file] = File.expand_path(@attributes[:file]) if abs_path
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def to_rubyscad
|
|
35
|
+
RubyScadBridge.new.import(@attributes)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def import(args)
|
|
40
|
+
Import.new(args)
|
|
41
|
+
end
|
|
42
|
+
end
|