crystalscad 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/ruby1.9.3
2
+ require "rubygems"
3
+ require "crystalscad"
4
+ include CrystalScad
5
+
6
+
7
+
8
+
9
+ res = knurled_cube([41,10,4])
10
+ #Total rendering time: 0 hours, 5 minutes, 53 seconds
11
+
12
+ #Total rendering time: 0 hours, 1 minutes, 41 seconds
13
+
14
+ #res = knurled_cylinder(d:16,h:10)
15
+
16
+
17
+
18
+ res.save("knurls.scad","$fn=64;")
19
+
data/lib/crystalscad.rb CHANGED
@@ -11,6 +11,7 @@ require 'crystalscad/ScrewThreads'
11
11
  require 'crystalscad/PrintedThreads'
12
12
  require 'crystalscad/Pipe'
13
13
  require 'crystalscad/Ruler'
14
+ require 'crystalscad/Extras'
14
15
 
15
16
  require 'crystalscad/CrystalScad'
16
17
 
@@ -24,7 +24,7 @@ module CrystalScad
24
24
  include CrystalScad::Gears
25
25
  include CrystalScad::ScrewThreads
26
26
  include CrystalScad::PrintedThreads
27
-
27
+ include CrystalScad::Extras
28
28
 
29
29
 
30
30
 
@@ -529,16 +529,27 @@ module CrystalScad
529
529
  def save_all(class_name,fn=$fn)
530
530
 
531
531
  res = class_name.send :new
532
- (res.methods.grep(/view/)+[:show,:output]).each do |i|
532
+ # regexp for output* view* show*
533
+ res.methods.grep(Regexp.union(/^output/,/^view/,/^show/)).each do |i|
534
+ output = nil
535
+
533
536
  res.send :initialize # ensure default values are loaded at each interation
534
- res.send i unless i == :show or i == :output # call the view method
535
- unless i == :output
536
- output = res.show
537
- else
538
- output = res.output
537
+ unless i == :show or i == :output # call the view method
538
+ output = res.send i
539
+ end
540
+
541
+ # if previous call resulted in a CrystalScadObject, don't call the show method again,
542
+ # otherwise call it.
543
+ unless output.kind_of? CrystalScadObject
544
+ unless i.to_s.include? "output"
545
+ output = res.show
546
+ else
547
+ output = res.output
548
+ end
539
549
  end
540
550
 
541
- output.save("output/#{res.class}_#{i}.scad","$fn=#{fn};")
551
+
552
+ output.save("output/#{res.class}_#{i}.scad","$fn=#{fn};") unless output == nil
542
553
  end
543
554
 
544
555
  end
@@ -21,6 +21,15 @@ module CrystalScad
21
21
  end
22
22
  alias :scad_output :walk_tree
23
23
 
24
+ def walk_tree_classes
25
+ res = []
26
+ @transformations.reverse.each{|trans|
27
+ res += trans.walk_tree_classes
28
+ }
29
+ res << self.class
30
+ res
31
+ end
32
+
24
33
  def to_rubyscad
25
34
  ""
26
35
  end
@@ -0,0 +1,108 @@
1
+ module CrystalScad::Extras
2
+
3
+
4
+ # This currently can solve triangels knowing 1 side and 2 angels
5
+ class Triangle
6
+ attr_accessor :alpha, :beta, :gamma, :a, :b, :c
7
+ def initialize(args={})
8
+ @alpha = args[:alpha]
9
+ @beta = args[:beta]
10
+ @gamma = args[:gamma]
11
+ @a = args[:a]
12
+ @b = args[:b]
13
+ @c = args[:c]
14
+ solve
15
+ end
16
+
17
+ def solve
18
+ # see if we have two angles, so we know the third one
19
+ if @alpha == nil and @beta != nil and @gamma != nil
20
+ @alpha = 180 - @beta - @gamma
21
+ elsif @alpha != nil and @beta == nil and @gamma != nil
22
+ @beta = 180 - @alpha - @gamma
23
+ elsif @alpha != nil and @beta != nil and @gamma == nil
24
+ @gamma = 180 - @alpha - @beta
25
+ end
26
+
27
+ if @alpha != nil and @beta != nil and @gamma != nil
28
+
29
+ if @a == nil
30
+ if @b != nil
31
+ @a = (@b / Math::sin(radians(@beta))) * Math::sin(radians(@alpha))
32
+ elsif @c != nil
33
+ @a = (@c / Math::sin(radians(@gamma))) * Math::sin(radians(@alpha))
34
+ end
35
+ end
36
+
37
+ if @b == nil
38
+ if @a != nil
39
+ @b = (@a / Math::sin(radians(@alpha))) * Math::sin(radians(@beta))
40
+ elsif @c != nil
41
+ @b = (@c / Math::sin(radians(@gamma))) * Math::sin(radians(@beta))
42
+ end
43
+ end
44
+
45
+ if @c == nil
46
+ if @a != nil
47
+ @c = (@a / Math::sin(radians(@alpha))) * Math::sin(radians(@gamma))
48
+ elsif @b != nil
49
+ @c = (@b / Math::sin(radians(@beta))) * Math::sin(radians(@gamma))
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+
56
+ end
57
+
58
+
59
+ end
60
+
61
+
62
+ def knurl(y)
63
+ x = 1.5
64
+ height = 1.5
65
+ res = cube(([x,y,height]))
66
+ res -= cylinder(d:0.9,h:height*1.42,fn:16).rotate(y:45).translate(x:0)
67
+ res -= cylinder(d:0.9,h:height*1.42,fn:16).rotate(y:-45).translate(x:1.5)
68
+
69
+ res
70
+ end
71
+
72
+
73
+ def knurled_cube(size)
74
+ x = size[0]
75
+ y = size[1]
76
+ z = size[2]
77
+ res = nil
78
+
79
+ (x / 1.5).ceil.times do |i|
80
+ (z / 1.5).ceil.times do |f|
81
+ res += knurl(y).translate(x:i*1.5,z:f*1.5)
82
+ end
83
+ end
84
+
85
+ res *= cube([x,y,z])
86
+
87
+
88
+ res
89
+ end
90
+
91
+
92
+ def knurled_cylinder(args={})
93
+ res = cylinder(args)
94
+ height = args[:h]
95
+ r = args[:d] / 2.0
96
+
97
+ 24.times do |i|
98
+ (height/2).ceil.times do |f|
99
+ res -= cylinder(d:0.9,h:height*2).rotate(y:45).translate(y:-r,z:f*2)
100
+ res -= cylinder(d:0.9,h:height*2).rotate(y:-45).translate(y:-r,z:f*2)
101
+ end
102
+ res.rotate(z:15)
103
+ end
104
+ res
105
+ end
106
+
107
+
108
+ end
@@ -1,4 +1,4 @@
1
1
  module CrystalScad
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crystalscad
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 6
10
- version: 0.5.6
9
+ - 7
10
+ version: 0.5.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joachim Glauche
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2015-04-17 00:00:00 Z
18
+ date: 2015-04-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rubyscad
@@ -96,6 +96,7 @@ files:
96
96
  - bin/crystalgen
97
97
  - crystalscad.gemspec
98
98
  - examples/gear.rb
99
+ - examples/knurls.rb
99
100
  - examples/openscad_examples/example001.rb
100
101
  - examples/openscad_examples/example002.rb
101
102
  - examples/openscad_examples/example003.rb
@@ -114,6 +115,7 @@ files:
114
115
  - lib/crystalscad/BillOfMaterial.rb
115
116
  - lib/crystalscad/CrystalScad.rb
116
117
  - lib/crystalscad/CrystalScadObject.rb
118
+ - lib/crystalscad/Extras.rb
117
119
  - lib/crystalscad/Gears.rb
118
120
  - lib/crystalscad/Hardware.rb
119
121
  - lib/crystalscad/LinearBearing.rb