rcad 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ # calculations are (mostly) from OpenSCAD MCAD library
2
+
3
+ require 'rcad'
4
+
5
+
6
+ class BaseBoltPart < Shape
7
+ attr_accessor :bolt_dia
8
+
9
+ def initialize(bolt_dia)
10
+ @bolt_dia = bolt_dia
11
+ end
12
+
13
+ def nut_height
14
+ 0.8 * bolt_dia
15
+ end
16
+
17
+ def nut_dia_across_flats
18
+ 1.8 * bolt_dia
19
+ end
20
+
21
+ def nut_dia_across_corners
22
+ nut_dia_across_flats / Math::cos(30.deg_to_rad)
23
+ end
24
+ end
25
+
26
+
27
+ class HexNut < BaseBoltPart
28
+ attr_accessor :xytol, :ztol, :full
29
+
30
+ def initialize(bolt_dia, xytol=0, ztol=0, full=false)
31
+ super(bolt_dia)
32
+
33
+ @xytol = xytol
34
+ @ztol = ztol
35
+ @full = full
36
+ end
37
+
38
+ def render
39
+ d = nut_dia_across_corners + @xytol
40
+ h = nut_height + @ztol
41
+
42
+ nut = reg_prism(6, d / 2.0, h)
43
+
44
+ if full
45
+ return nut
46
+ else
47
+ return sub do
48
+ ~nut
49
+ ~cylinder(h + 0.02, bolt_dia + @xytol)
50
+ .move_z(-0.01)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+
57
+ class Bolt < BaseBoltPart
58
+ attr_accessor :bolt_len, :xytol, :ztol
59
+
60
+ def initialize(bolt_dia, bolt_len, xytol=0, ztol=0)
61
+ super(bolt_dia)
62
+
63
+ @bolt_len = bolt_len
64
+ @xytol = xytol
65
+ @ztol = ztol
66
+ end
67
+
68
+ def head_height
69
+ 0.7 * bolt_dia
70
+ end
71
+
72
+ def total_len
73
+ bolt_len + head_height
74
+ end
75
+
76
+ def render
77
+ d = nut_dia_across_corners + @xytol
78
+ h = head_height + @ztol
79
+ head = reg_prism(6, d / 2.0, h)
80
+
81
+ add do
82
+ ~head
83
+ ~cylinder(total_len + @ztol, bolt_dia + @xytol)
84
+ .move_z(-head_height)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module Rcad
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'rcad'
2
+
3
+
4
+ base = box(10.cm, 10.cm, 3.cm)
5
+ .move(-5.cm, -5.cm, 0)
6
+
7
+ pedestal = base
8
+ .add(cylinder(8.cm, 7.cm).move_z(3.cm))
9
+ .add(base.move_z(3.cm + 7.cm))
10
+
11
+ pedestal
12
+ .rot_z(45)
13
+ .write_stl("pedestal.stl")
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rcad/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rcad"
8
+ spec.version = Rcad::VERSION
9
+ spec.authors = ["Y. Sapir"]
10
+ spec.email = ["yasapir@gmail.com"]
11
+ spec.description = %q{Solid CAD programming library}
12
+ spec.summary = %q{Ruby CAD library}
13
+ spec.homepage = "http://github.com/sapir/rcad"
14
+ # TODO: choose a license: spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.extensions = ['ext/_rcad/extconf.rb']
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rake-compiler", "~> 0.8.3"
26
+ spec.add_development_dependency "rice", "~> 1.5.3"
27
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rcad
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Y. Sapir
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake-compiler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: rice
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.5.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.5.3
78
+ description: Solid CAD programming library
79
+ email:
80
+ - yasapir@gmail.com
81
+ executables: []
82
+ extensions:
83
+ - ext/_rcad/extconf.rb
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - README.md
89
+ - Rakefile
90
+ - ext/_rcad/_rcad.cpp
91
+ - ext/_rcad/extconf.rb
92
+ - lib/rcad.rb
93
+ - lib/rcad/gears.rb
94
+ - lib/rcad/nuts.rb
95
+ - lib/rcad/version.rb
96
+ - pedestal.rb
97
+ - rcad.gemspec
98
+ homepage: http://github.com/sapir/rcad
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.23
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Ruby CAD library
122
+ test_files: []