Top Level Namespace
Defined Under Namespace
Modules: Interpolation, Ruby3mf
Classes: ContentTypes, Document, EdgeList, Log3mf, MeshAnalyzer, MeshNormalAnalyzer, Model3mf, Relationships, SchemaFiles, Texture3mf, Thumbnail3mf, XmlVal
Instance Method Summary
collapse
Instance Method Details
#angle_between(a, b) ⇒ Object
185
186
187
188
|
# File 'lib/ruby3mf/mesh_normal_analyzer.rb', line 185
def angle_between(a, b)
cos_theta = dot_product(a, b) / (magnitude(a) * magnitude(b))
Math.acos(cos_theta)
end
|
#cross_product(a, b) ⇒ Object
Various utility functions
160
161
162
163
164
165
166
167
|
# File 'lib/ruby3mf/mesh_normal_analyzer.rb', line 160
def cross_product(a, b)
result = [0, 0, 0]
result[0] = a[1]*b[2] - a[2]*b[1]
result[1] = a[2]*b[0] - a[0]*b[2]
result[2] = a[0]*b[1] - a[1]*b[0]
result
end
|
#dot_product(a, b) ⇒ Object
169
170
171
|
# File 'lib/ruby3mf/mesh_normal_analyzer.rb', line 169
def dot_product(a, b)
a[0]*b[0] + a[1]*b[1] + a[2]*b[2]
end
|
#equal(a, b) ⇒ Object
181
182
183
|
# File 'lib/ruby3mf/mesh_normal_analyzer.rb', line 181
def equal(a, b)
(a[0] - b[0]).abs < 0.0001 && (a[1] - b[1]).abs < 0.0001 && (a[2] - b[2]).abs < 0.0001
end
|
#magnitude(a) ⇒ Object
177
178
179
|
# File 'lib/ruby3mf/mesh_normal_analyzer.rb', line 177
def magnitude(a)
Math.sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2])
end
|
#normalize(a) ⇒ Object
190
191
192
193
|
# File 'lib/ruby3mf/mesh_normal_analyzer.rb', line 190
def normalize(a)
length = magnitude(a)
[a[0]/length, a[1]/length, a[2]/length]
end
|
#point_cloud_center(vertices) ⇒ Object
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/ruby3mf/mesh_normal_analyzer.rb', line 195
def point_cloud_center(vertices)
if vertices.count < 1
return [0, 0, 0]
end
vertex = vertices[0]
min_x = max_x = vertex[0]
min_y = max_y = vertex[1]
min_z = max_z = vertex[2]
vertices.each do |vertex|
x = vertex[0]
y = vertex[1]
z = vertex[2]
min_x = x if x < min_x
max_x = x if x > max_x
min_y = y if y < min_y
max_y = y if y > max_y
min_z = z if z < min_z
max_z = z if z > max_z
end
[(min_x + max_x) / 2.0, (min_y + max_y) / 2.0, (min_z + max_z) / 2.0]
end
|
#vector_to(a, b) ⇒ Object
173
174
175
|
# File 'lib/ruby3mf/mesh_normal_analyzer.rb', line 173
def vector_to(a, b)
[b[0] - a[0], b[1] - a[1], b[2] - a[2]]
end
|