silicium 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +4 -0
- data/.gitignore +13 -0
- data/.travis.yml +25 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/Makefile +269 -0
- data/README.md +46 -0
- data/Rakefile +17 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Object.html +117 -0
- data/docs/README_md.html +142 -0
- data/docs/Silicium/Combinatorics.html +270 -0
- data/docs/Silicium/Dice/Polyhedron.html +315 -0
- data/docs/Silicium/Dice/PolyhedronSet.html +321 -0
- data/docs/Silicium/Dice.html +99 -0
- data/docs/Silicium/Error.html +106 -0
- data/docs/Silicium/Geometry/Line2dCanon.html +243 -0
- data/docs/Silicium/Geometry/VariablesOrderException.html +106 -0
- data/docs/Silicium/Geometry.html +940 -0
- data/docs/Silicium/Graphs/GraphError.html +106 -0
- data/docs/Silicium/Graphs/OrientedGraph.html +775 -0
- data/docs/Silicium/Graphs/UnorientedGraph.html +284 -0
- data/docs/Silicium/Graphs.html +164 -0
- data/docs/Silicium/IntegralDoesntExistError.html +106 -0
- data/docs/Silicium/NumericalIntegration.html +521 -0
- data/docs/Silicium/Optimization.html +639 -0
- data/docs/Silicium/Plotter/Image.html +297 -0
- data/docs/Silicium/Plotter.html +186 -0
- data/docs/Silicium.html +101 -0
- data/docs/created.rid +9 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +619 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +132 -0
- data/docs/js/darkfish.js +84 -0
- data/docs/js/navigation.js +105 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +110 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +608 -0
- data/lib/geometry.rb +236 -0
- data/lib/graph.rb +164 -0
- data/lib/numerical_integration.rb +147 -0
- data/lib/optimization.rb +144 -0
- data/lib/plotter.rb +96 -0
- data/lib/silicium/version.rb +3 -0
- data/lib/silicium.rb +5 -0
- data/lib/theory_of_probability.rb +227 -0
- data/silicium.gemspec +39 -0
- metadata +185 -0
@@ -0,0 +1,940 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>module Silicium::Geometry - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../";
|
11
|
+
var index_rel_prefix = "../";
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<script src="../js/navigation.js" defer></script>
|
15
|
+
<script src="../js/search.js" defer></script>
|
16
|
+
<script src="../js/search_index.js" defer></script>
|
17
|
+
<script src="../js/searcher.js" defer></script>
|
18
|
+
<script src="../js/darkfish.js" defer></script>
|
19
|
+
|
20
|
+
<link href="../css/fonts.css" rel="stylesheet">
|
21
|
+
<link href="../css/rdoc.css" rel="stylesheet">
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
<body id="top" role="document" class="module">
|
27
|
+
<nav role="navigation">
|
28
|
+
<div id="project-navigation">
|
29
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
30
|
+
<h2>
|
31
|
+
<a href="../index.html" rel="home">Home</a>
|
32
|
+
</h2>
|
33
|
+
|
34
|
+
<div id="table-of-contents-navigation">
|
35
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
36
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
37
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
42
|
+
<form action="#" method="get" accept-charset="utf-8">
|
43
|
+
<div id="search-field-wrapper">
|
44
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
45
|
+
aria-autocomplete="list" aria-controls="search-results"
|
46
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
47
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<ul id="search-results" aria-label="Search Results"
|
51
|
+
aria-busy="false" aria-expanded="false"
|
52
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
53
|
+
</form>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
<div id="class-metadata">
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
<!-- Method Quickref -->
|
66
|
+
<div id="method-list-section" class="nav-section">
|
67
|
+
<h3>Methods</h3>
|
68
|
+
|
69
|
+
<ul class="link-list" role="directory">
|
70
|
+
|
71
|
+
<li ><a href="#method-i-clockwise">#clockwise</a>
|
72
|
+
|
73
|
+
<li ><a href="#method-i-counter_clockwise">#counter_clockwise</a>
|
74
|
+
|
75
|
+
<li ><a href="#method-i-cut_by_eq">#cut_by_eq</a>
|
76
|
+
|
77
|
+
<li ><a href="#method-i-directing_vector3d">#directing_vector3d</a>
|
78
|
+
|
79
|
+
<li ><a href="#method-i-distance_point_line2d">#distance_point_line2d</a>
|
80
|
+
|
81
|
+
<li ><a href="#method-i-distance_point_line_equation2d">#distance_point_line_equation2d</a>
|
82
|
+
|
83
|
+
<li ><a href="#method-i-distance_point_to_point2d">#distance_point_to_point2d</a>
|
84
|
+
|
85
|
+
<li ><a href="#method-i-distance_point_to_point3d">#distance_point_to_point3d</a>
|
86
|
+
|
87
|
+
<li ><a href="#method-i-height_point_3d">#height_point_3d</a>
|
88
|
+
|
89
|
+
<li ><a href="#method-i-insert_eq">#insert_eq</a>
|
90
|
+
|
91
|
+
<li ><a href="#method-i-minimal_convex_hull_2d">#minimal_convex_hull_2d</a>
|
92
|
+
|
93
|
+
<li ><a href="#method-i-needed_variables_order-3F">#needed_variables_order?</a>
|
94
|
+
|
95
|
+
<li ><a href="#method-i-not_polygon-3F">#not_polygon?</a>
|
96
|
+
|
97
|
+
<li ><a href="#method-i-oriented_area">#oriented_area</a>
|
98
|
+
|
99
|
+
<li ><a href="#method-i-point_to_line_distance_3d">#point_to_line_distance_3d</a>
|
100
|
+
|
101
|
+
<li ><a href="#method-i-process_cf">#process_cf</a>
|
102
|
+
|
103
|
+
<li ><a href="#method-i-process_free_member">#process_free_member</a>
|
104
|
+
|
105
|
+
<li ><a href="#method-i-process_line_by_coordinates">#process_line_by_coordinates</a>
|
106
|
+
|
107
|
+
<li ><a href="#method-i-put_point_in_part">#put_point_in_part</a>
|
108
|
+
|
109
|
+
<li ><a href="#method-i-vector_length">#vector_length</a>
|
110
|
+
|
111
|
+
<li ><a href="#method-i-vectors_product">#vectors_product</a>
|
112
|
+
|
113
|
+
</ul>
|
114
|
+
</div>
|
115
|
+
|
116
|
+
</div>
|
117
|
+
</nav>
|
118
|
+
|
119
|
+
<main role="main" aria-labelledby="module-Silicium::Geometry">
|
120
|
+
<h1 id="module-Silicium::Geometry" class="module">
|
121
|
+
module Silicium::Geometry
|
122
|
+
</h1>
|
123
|
+
|
124
|
+
<section class="description">
|
125
|
+
|
126
|
+
</section>
|
127
|
+
|
128
|
+
|
129
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
<section class="constants-list">
|
136
|
+
<header>
|
137
|
+
<h3>Constants</h3>
|
138
|
+
</header>
|
139
|
+
<dl>
|
140
|
+
|
141
|
+
<dt id="Point">Point
|
142
|
+
|
143
|
+
<dd><p>Represents a point as two coordinates in two-dimensional space</p>
|
144
|
+
|
145
|
+
|
146
|
+
<dt id="Point3d">Point3d
|
147
|
+
|
148
|
+
<dd><p>Represents a point as three coordinates in three-dimensional space</p>
|
149
|
+
|
150
|
+
|
151
|
+
</dl>
|
152
|
+
</section>
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
159
|
+
<header>
|
160
|
+
<h3>Public Instance Methods</h3>
|
161
|
+
</header>
|
162
|
+
|
163
|
+
|
164
|
+
<div id="method-i-clockwise" class="method-detail ">
|
165
|
+
|
166
|
+
<div class="method-heading">
|
167
|
+
<span class="method-name">clockwise</span><span
|
168
|
+
class="method-args">(a, b, c)</span>
|
169
|
+
|
170
|
+
<span class="method-click-advice">click to toggle source</span>
|
171
|
+
|
172
|
+
</div>
|
173
|
+
|
174
|
+
|
175
|
+
<div class="method-description">
|
176
|
+
|
177
|
+
<p>Determines if a clockwise crawl is performed for defined order of points</p>
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
<div class="method-source-code" id="clockwise-source">
|
183
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 83</span>
|
184
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">clockwise</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>)
|
185
|
+
<span class="ruby-identifier">oriented_area</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>).<span class="ruby-identifier">negative?</span>
|
186
|
+
<span class="ruby-keyword">end</span></pre>
|
187
|
+
</div>
|
188
|
+
|
189
|
+
</div>
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
</div>
|
195
|
+
|
196
|
+
|
197
|
+
<div id="method-i-counter_clockwise" class="method-detail ">
|
198
|
+
|
199
|
+
<div class="method-heading">
|
200
|
+
<span class="method-name">counter_clockwise</span><span
|
201
|
+
class="method-args">(a, b, c)</span>
|
202
|
+
|
203
|
+
<span class="method-click-advice">click to toggle source</span>
|
204
|
+
|
205
|
+
</div>
|
206
|
+
|
207
|
+
|
208
|
+
<div class="method-description">
|
209
|
+
|
210
|
+
<p>Determines if a counter-clockwise crawl is performed for defined order of points</p>
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
<div class="method-source-code" id="counter_clockwise-source">
|
216
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 90</span>
|
217
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">counter_clockwise</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>)
|
218
|
+
<span class="ruby-identifier">oriented_area</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>).<span class="ruby-identifier">positive?</span>
|
219
|
+
<span class="ruby-keyword">end</span></pre>
|
220
|
+
</div>
|
221
|
+
|
222
|
+
</div>
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
</div>
|
228
|
+
|
229
|
+
|
230
|
+
<div id="method-i-cut_by_eq" class="method-detail ">
|
231
|
+
|
232
|
+
<div class="method-heading">
|
233
|
+
<span class="method-name">cut_by_eq</span><span
|
234
|
+
class="method-args">(line_equation)</span>
|
235
|
+
|
236
|
+
<span class="method-click-advice">click to toggle source</span>
|
237
|
+
|
238
|
+
</div>
|
239
|
+
|
240
|
+
|
241
|
+
<div class="method-description">
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
<div class="method-source-code" id="cut_by_eq-source">
|
249
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 147</span>
|
250
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">cut_by_eq</span>(<span class="ruby-identifier">line_equation</span>)
|
251
|
+
<span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">index</span>(<span class="ruby-string">'='</span>), <span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">length</span>).<span class="ruby-identifier">sub</span>(<span class="ruby-string">'='</span>, <span class="ruby-string">''</span>)
|
252
|
+
<span class="ruby-keyword">end</span></pre>
|
253
|
+
</div>
|
254
|
+
|
255
|
+
</div>
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
</div>
|
261
|
+
|
262
|
+
|
263
|
+
<div id="method-i-directing_vector3d" class="method-detail ">
|
264
|
+
|
265
|
+
<div class="method-heading">
|
266
|
+
<span class="method-name">directing_vector3d</span><span
|
267
|
+
class="method-args">(line_equation)</span>
|
268
|
+
|
269
|
+
<span class="method-click-advice">click to toggle source</span>
|
270
|
+
|
271
|
+
</div>
|
272
|
+
|
273
|
+
|
274
|
+
<div class="method-description">
|
275
|
+
|
276
|
+
<p>Creates an array- directing vector in three-dimensional space . The equation is specified in the canonical form. Example, (x-0) / 26 = (y + 300) / * (- 15) = (z-200) / 51</p>
|
277
|
+
|
278
|
+
<p>Important: mandatory order of variables: x, y, z</p>
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
<div class="method-source-code" id="directing_vector3d-source">
|
284
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 169</span>
|
285
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">directing_vector3d</span>(<span class="ruby-identifier">line_equation</span>)
|
286
|
+
<span class="ruby-identifier">process_line_by_coordinates</span>(<span class="ruby-identifier">line_equation</span>, <span class="ruby-value">:process_cf</span>)
|
287
|
+
<span class="ruby-keyword">end</span></pre>
|
288
|
+
</div>
|
289
|
+
|
290
|
+
</div>
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
</div>
|
296
|
+
|
297
|
+
|
298
|
+
<div id="method-i-distance_point_line2d" class="method-detail ">
|
299
|
+
|
300
|
+
<div class="method-heading">
|
301
|
+
<span class="method-name">distance_point_line2d</span><span
|
302
|
+
class="method-args">(p1, p2, a)</span>
|
303
|
+
|
304
|
+
<span class="method-click-advice">click to toggle source</span>
|
305
|
+
|
306
|
+
</div>
|
307
|
+
|
308
|
+
|
309
|
+
<div class="method-description">
|
310
|
+
|
311
|
+
<p>The distance from a point to a line on a plane The line is defined by two points <a href="https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line">en.wikipedia.org/wiki/Distance_from_a_point_to_a_line</a></p>
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
<div class="method-source-code" id="distance_point_line2d-source">
|
317
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 60</span>
|
318
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">distance_point_line2d</span>(<span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>, <span class="ruby-identifier">a</span>)
|
319
|
+
<span class="ruby-identifier">line_segment_length</span> = <span class="ruby-identifier">distance_point_to_point2d</span>(<span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>)
|
320
|
+
((<span class="ruby-identifier">p2</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p1</span>.<span class="ruby-identifier">y</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">x</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">p2</span>.<span class="ruby-identifier">x</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p1</span>.<span class="ruby-identifier">x</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">p2</span>.<span class="ruby-identifier">x</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">p1</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p2</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">p1</span>.<span class="ruby-identifier">x</span>).<span class="ruby-identifier">abs</span> <span class="ruby-operator">/</span> (<span class="ruby-identifier">line_segment_length</span> <span class="ruby-operator">*</span> <span class="ruby-value">1.0</span>)
|
321
|
+
<span class="ruby-keyword">end</span></pre>
|
322
|
+
</div>
|
323
|
+
|
324
|
+
</div>
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
</div>
|
330
|
+
|
331
|
+
|
332
|
+
<div id="method-i-distance_point_line_equation2d" class="method-detail ">
|
333
|
+
|
334
|
+
<div class="method-heading">
|
335
|
+
<span class="method-name">distance_point_line_equation2d</span><span
|
336
|
+
class="method-args">(a, b, c, p)</span>
|
337
|
+
|
338
|
+
<span class="method-click-advice">click to toggle source</span>
|
339
|
+
|
340
|
+
</div>
|
341
|
+
|
342
|
+
|
343
|
+
<div class="method-description">
|
344
|
+
|
345
|
+
<p>The distance from a point to a line on a plane Line defined by an equation return 0 if the equation does not define a line.</p>
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
<div class="method-source-code" id="distance_point_line_equation2d-source">
|
351
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 69</span>
|
352
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">distance_point_line_equation2d</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>, <span class="ruby-identifier">p</span>)
|
353
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
354
|
+
<span class="ruby-keyword">return</span> <span class="ruby-value">0</span>
|
355
|
+
<span class="ruby-keyword">end</span>
|
356
|
+
(<span class="ruby-identifier">a</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">p</span>.<span class="ruby-identifier">x</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">p</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">c</span>).<span class="ruby-identifier">abs</span> <span class="ruby-operator">/</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">sqrt</span>(<span class="ruby-identifier">a</span><span class="ruby-operator">**</span><span class="ruby-value">2</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span><span class="ruby-operator">**</span><span class="ruby-value">2</span>)
|
357
|
+
<span class="ruby-keyword">end</span></pre>
|
358
|
+
</div>
|
359
|
+
|
360
|
+
</div>
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
</div>
|
366
|
+
|
367
|
+
|
368
|
+
<div id="method-i-distance_point_to_point2d" class="method-detail ">
|
369
|
+
|
370
|
+
<div class="method-heading">
|
371
|
+
<span class="method-name">distance_point_to_point2d</span><span
|
372
|
+
class="method-args">(a, b)</span>
|
373
|
+
|
374
|
+
<span class="method-click-advice">click to toggle source</span>
|
375
|
+
|
376
|
+
</div>
|
377
|
+
|
378
|
+
|
379
|
+
<div class="method-description">
|
380
|
+
|
381
|
+
<p>Calculates the distance from given points in two-dimensional space</p>
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
<div class="method-source-code" id="distance_point_to_point2d-source">
|
387
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 19</span>
|
388
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">distance_point_to_point2d</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>)
|
389
|
+
<span class="ruby-constant">Math</span>.<span class="ruby-identifier">sqrt</span>((<span class="ruby-identifier">b</span>.<span class="ruby-identifier">x</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">x</span>)<span class="ruby-operator">**</span><span class="ruby-value">2</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">b</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">y</span>)<span class="ruby-operator">**</span><span class="ruby-value">2</span>)
|
390
|
+
<span class="ruby-keyword">end</span></pre>
|
391
|
+
</div>
|
392
|
+
|
393
|
+
</div>
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
</div>
|
399
|
+
|
400
|
+
|
401
|
+
<div id="method-i-distance_point_to_point3d" class="method-detail ">
|
402
|
+
|
403
|
+
<div class="method-heading">
|
404
|
+
<span class="method-name">distance_point_to_point3d</span><span
|
405
|
+
class="method-args">(a, b)</span>
|
406
|
+
|
407
|
+
<span class="method-click-advice">click to toggle source</span>
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
|
412
|
+
<div class="method-description">
|
413
|
+
|
414
|
+
<p>Calculates the distance from given points in three-dimensional space</p>
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
<div class="method-source-code" id="distance_point_to_point3d-source">
|
420
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 52</span>
|
421
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">distance_point_to_point3d</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>)
|
422
|
+
<span class="ruby-constant">Math</span>.<span class="ruby-identifier">sqrt</span>((<span class="ruby-identifier">b</span>.<span class="ruby-identifier">x</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">x</span>)<span class="ruby-operator">**</span><span class="ruby-value">2</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">b</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">y</span>)<span class="ruby-operator">**</span><span class="ruby-value">2</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">b</span>.<span class="ruby-identifier">z</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">z</span>)<span class="ruby-operator">**</span><span class="ruby-value">2</span>)
|
423
|
+
<span class="ruby-keyword">end</span></pre>
|
424
|
+
</div>
|
425
|
+
|
426
|
+
</div>
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
</div>
|
432
|
+
|
433
|
+
|
434
|
+
<div id="method-i-height_point_3d" class="method-detail ">
|
435
|
+
|
436
|
+
<div class="method-heading">
|
437
|
+
<span class="method-name">height_point_3d</span><span
|
438
|
+
class="method-args">(line_equation)</span>
|
439
|
+
|
440
|
+
<span class="method-click-advice">click to toggle source</span>
|
441
|
+
|
442
|
+
</div>
|
443
|
+
|
444
|
+
|
445
|
+
<div class="method-description">
|
446
|
+
|
447
|
+
<p>Creates an array of coordinates of the point ([x, y, z] on the line given by the equation in the canonical form. Example, (x-0) / 26 = (y + 300) / * (- 15) = (z-200) / 51</p>
|
448
|
+
|
449
|
+
<p>Important: mandatory order of variables: x, y, z</p>
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
|
454
|
+
<div class="method-source-code" id="height_point_3d-source">
|
455
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 201</span>
|
456
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">height_point_3d</span>(<span class="ruby-identifier">line_equation</span>)
|
457
|
+
<span class="ruby-identifier">process_line_by_coordinates</span>(<span class="ruby-identifier">line_equation</span>, <span class="ruby-value">:process_free_member</span>)
|
458
|
+
<span class="ruby-keyword">end</span></pre>
|
459
|
+
</div>
|
460
|
+
|
461
|
+
</div>
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
|
466
|
+
</div>
|
467
|
+
|
468
|
+
|
469
|
+
<div id="method-i-insert_eq" class="method-detail ">
|
470
|
+
|
471
|
+
<div class="method-heading">
|
472
|
+
<span class="method-name">insert_eq</span><span
|
473
|
+
class="method-args">(line_equation)</span>
|
474
|
+
|
475
|
+
<span class="method-click-advice">click to toggle source</span>
|
476
|
+
|
477
|
+
</div>
|
478
|
+
|
479
|
+
|
480
|
+
<div class="method-description">
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
<div class="method-source-code" id="insert_eq-source">
|
488
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 232</span>
|
489
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">insert_eq</span>(<span class="ruby-identifier">line_equation</span>)
|
490
|
+
<span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-string">' '</span>, <span class="ruby-string">''</span>).<span class="ruby-identifier">insert</span>(<span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">length</span>, <span class="ruby-string">'='</span>)
|
491
|
+
<span class="ruby-keyword">end</span></pre>
|
492
|
+
</div>
|
493
|
+
|
494
|
+
</div>
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
</div>
|
500
|
+
|
501
|
+
|
502
|
+
<div id="method-i-minimal_convex_hull_2d" class="method-detail ">
|
503
|
+
|
504
|
+
<div class="method-heading">
|
505
|
+
<span class="method-name">minimal_convex_hull_2d</span><span
|
506
|
+
class="method-args">(points)</span>
|
507
|
+
|
508
|
+
<span class="method-click-advice">click to toggle source</span>
|
509
|
+
|
510
|
+
</div>
|
511
|
+
|
512
|
+
|
513
|
+
<div class="method-description">
|
514
|
+
|
515
|
+
<p>Returns an array containing points that are included in the minimal convex hull for a given array of points <a href="https://e-maxx.ru/algo/convex_hull_graham">e-maxx.ru/algo/convex_hull_graham</a></p>
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
|
520
|
+
<div class="method-source-code" id="minimal_convex_hull_2d-source">
|
521
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 110</span>
|
522
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">minimal_convex_hull_2d</span>(<span class="ruby-identifier">points</span>)
|
523
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">points</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">not_polygon?</span>(<span class="ruby-identifier">points</span>)
|
524
|
+
|
525
|
+
<span class="ruby-identifier">points</span>.<span class="ruby-identifier">sort_by!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">p</span>.<span class="ruby-identifier">x</span>, <span class="ruby-identifier">p</span>.<span class="ruby-identifier">y</span>] }
|
526
|
+
<span class="ruby-identifier">first</span> = <span class="ruby-identifier">points</span>[<span class="ruby-value">0</span>]
|
527
|
+
<span class="ruby-identifier">last</span> = <span class="ruby-identifier">points</span>.<span class="ruby-identifier">last</span>
|
528
|
+
<span class="ruby-identifier">up</span> = [<span class="ruby-identifier">first</span>]
|
529
|
+
<span class="ruby-identifier">down</span> = [<span class="ruby-identifier">first</span>]
|
530
|
+
|
531
|
+
(<span class="ruby-value">1</span><span class="ruby-operator">...</span><span class="ruby-identifier">points</span>.<span class="ruby-identifier">size</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
532
|
+
<span class="ruby-identifier">point</span> = <span class="ruby-identifier">points</span>[<span class="ruby-identifier">i</span>]
|
533
|
+
<span class="ruby-identifier">is_last</span> = <span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">points</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
|
534
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">is_last</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">clockwise</span>(<span class="ruby-identifier">first</span>, <span class="ruby-identifier">point</span>, <span class="ruby-identifier">last</span>)
|
535
|
+
<span class="ruby-identifier">put_point_in_part</span>(<span class="ruby-identifier">up</span>, <span class="ruby-identifier">point</span>, <span class="ruby-value">:clockwise</span>)
|
536
|
+
<span class="ruby-keyword">end</span>
|
537
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">is_last</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">counter_clockwise</span>(<span class="ruby-identifier">first</span>, <span class="ruby-identifier">point</span>, <span class="ruby-identifier">last</span>)
|
538
|
+
<span class="ruby-identifier">put_point_in_part</span>(<span class="ruby-identifier">down</span>, <span class="ruby-identifier">point</span>, <span class="ruby-value">:counter_clockwise</span>)
|
539
|
+
<span class="ruby-keyword">end</span>
|
540
|
+
<span class="ruby-keyword">end</span>
|
541
|
+
|
542
|
+
<span class="ruby-identifier">hull</span> = <span class="ruby-identifier">up</span>
|
543
|
+
(<span class="ruby-value">1</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">down</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">2</span>)).<span class="ruby-identifier">reverse_each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
|
544
|
+
<span class="ruby-identifier">hull</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">down</span>[<span class="ruby-identifier">j</span>])
|
545
|
+
<span class="ruby-keyword">end</span>
|
546
|
+
<span class="ruby-identifier">hull</span>
|
547
|
+
<span class="ruby-keyword">end</span></pre>
|
548
|
+
</div>
|
549
|
+
|
550
|
+
</div>
|
551
|
+
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
</div>
|
556
|
+
|
557
|
+
|
558
|
+
<div id="method-i-needed_variables_order-3F" class="method-detail ">
|
559
|
+
|
560
|
+
<div class="method-heading">
|
561
|
+
<span class="method-name">needed_variables_order?</span><span
|
562
|
+
class="method-args">(before, after)</span>
|
563
|
+
|
564
|
+
<span class="method-click-advice">click to toggle source</span>
|
565
|
+
|
566
|
+
</div>
|
567
|
+
|
568
|
+
|
569
|
+
<div class="method-description">
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
|
576
|
+
<div class="method-source-code" id="needed_variables_order-3F-source">
|
577
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 176</span>
|
578
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">needed_variables_order?</span>(<span class="ruby-identifier">before</span>, <span class="ruby-identifier">after</span>)
|
579
|
+
<span class="ruby-identifier">before</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">after</span>
|
580
|
+
<span class="ruby-keyword">end</span></pre>
|
581
|
+
</div>
|
582
|
+
|
583
|
+
</div>
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
|
588
|
+
</div>
|
589
|
+
|
590
|
+
|
591
|
+
<div id="method-i-not_polygon-3F" class="method-detail ">
|
592
|
+
|
593
|
+
<div class="method-heading">
|
594
|
+
<span class="method-name">not_polygon?</span><span
|
595
|
+
class="method-args">(points)</span>
|
596
|
+
|
597
|
+
<span class="method-click-advice">click to toggle source</span>
|
598
|
+
|
599
|
+
</div>
|
600
|
+
|
601
|
+
|
602
|
+
<div class="method-description">
|
603
|
+
|
604
|
+
|
605
|
+
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
<div class="method-source-code" id="not_polygon-3F-source">
|
610
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 94</span>
|
611
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">not_polygon?</span>(<span class="ruby-identifier">points</span>)
|
612
|
+
<span class="ruby-identifier">points</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">points</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">points</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span>
|
613
|
+
<span class="ruby-keyword">end</span></pre>
|
614
|
+
</div>
|
615
|
+
|
616
|
+
</div>
|
617
|
+
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
</div>
|
622
|
+
|
623
|
+
|
624
|
+
<div id="method-i-oriented_area" class="method-detail ">
|
625
|
+
|
626
|
+
<div class="method-heading">
|
627
|
+
<span class="method-name">oriented_area</span><span
|
628
|
+
class="method-args">(a, b, c)</span>
|
629
|
+
|
630
|
+
<span class="method-click-advice">click to toggle source</span>
|
631
|
+
|
632
|
+
</div>
|
633
|
+
|
634
|
+
|
635
|
+
<div class="method-description">
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
|
640
|
+
|
641
|
+
|
642
|
+
<div class="method-source-code" id="oriented_area-source">
|
643
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 76</span>
|
644
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">oriented_area</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>)
|
645
|
+
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">x</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">b</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">y</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">x</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">c</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">y</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">x</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">a</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">y</span>)
|
646
|
+
<span class="ruby-keyword">end</span></pre>
|
647
|
+
</div>
|
648
|
+
|
649
|
+
</div>
|
650
|
+
|
651
|
+
|
652
|
+
|
653
|
+
|
654
|
+
</div>
|
655
|
+
|
656
|
+
|
657
|
+
<div id="method-i-point_to_line_distance_3d" class="method-detail ">
|
658
|
+
|
659
|
+
<div class="method-heading">
|
660
|
+
<span class="method-name">point_to_line_distance_3d</span><span
|
661
|
+
class="method-args">(point, line_eq)</span>
|
662
|
+
|
663
|
+
<span class="method-click-advice">click to toggle source</span>
|
664
|
+
|
665
|
+
</div>
|
666
|
+
|
667
|
+
|
668
|
+
<div class="method-description">
|
669
|
+
|
670
|
+
<p>Calculates the distance from a point given by a <a href="Geometry.html#Point3d"><code>Point3d</code></a> structure to a straight line given by a canonical equation. Example, (x-0) / 26 = (y + 300) / * (- 15) = (z-200) / 51</p>
|
671
|
+
|
672
|
+
<p>Important: mandatory order of variables: x, y, z</p>
|
673
|
+
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
<div class="method-source-code" id="point_to_line_distance_3d-source">
|
678
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 223</span>
|
679
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">point_to_line_distance_3d</span>(<span class="ruby-identifier">point</span>, <span class="ruby-identifier">line_eq</span>)
|
680
|
+
<span class="ruby-identifier">dir_vector</span> = <span class="ruby-identifier">directing_vector3d</span>(<span class="ruby-identifier">line_eq</span>)
|
681
|
+
<span class="ruby-identifier">line_point</span> = <span class="ruby-identifier">height_point_3d</span>(<span class="ruby-identifier">line_eq</span>)
|
682
|
+
<span class="ruby-identifier">height_vector</span> = [<span class="ruby-identifier">line_point</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">point</span>.<span class="ruby-identifier">x</span>, <span class="ruby-identifier">line_point</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">point</span>.<span class="ruby-identifier">y</span>, <span class="ruby-identifier">line_point</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">point</span>.<span class="ruby-identifier">z</span>]
|
683
|
+
|
684
|
+
<span class="ruby-identifier">height_on_dir</span> = <span class="ruby-identifier">vectors_product</span>(<span class="ruby-identifier">height_vector</span>, <span class="ruby-identifier">dir_vector</span>)
|
685
|
+
<span class="ruby-identifier">vector_length</span>(<span class="ruby-identifier">height_on_dir</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">vector_length</span>(<span class="ruby-identifier">dir_vector</span>)
|
686
|
+
<span class="ruby-keyword">end</span></pre>
|
687
|
+
</div>
|
688
|
+
|
689
|
+
</div>
|
690
|
+
|
691
|
+
|
692
|
+
|
693
|
+
|
694
|
+
</div>
|
695
|
+
|
696
|
+
|
697
|
+
<div id="method-i-process_cf" class="method-detail ">
|
698
|
+
|
699
|
+
<div class="method-heading">
|
700
|
+
<span class="method-name">process_cf</span><span
|
701
|
+
class="method-args">(line_equation, variable)</span>
|
702
|
+
|
703
|
+
<span class="method-click-advice">click to toggle source</span>
|
704
|
+
|
705
|
+
</div>
|
706
|
+
|
707
|
+
|
708
|
+
<div class="method-description">
|
709
|
+
|
710
|
+
|
711
|
+
|
712
|
+
|
713
|
+
|
714
|
+
|
715
|
+
<div class="method-source-code" id="process_cf-source">
|
716
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 137</span>
|
717
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">process_cf</span>(<span class="ruby-identifier">line_equation</span>, <span class="ruby-identifier">variable</span>)
|
718
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">variable</span>)
|
719
|
+
<span class="ruby-identifier">before</span> = <span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">index</span>(<span class="ruby-string">'/'</span>) <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
|
720
|
+
<span class="ruby-identifier">after</span> = <span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">index</span>(<span class="ruby-string">'='</span>)
|
721
|
+
<span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">before</span><span class="ruby-operator">..</span><span class="ruby-identifier">after</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-string">'='</span>, <span class="ruby-string">''</span>).<span class="ruby-identifier">sub</span>(<span class="ruby-string">'*'</span>, <span class="ruby-string">''</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-string">'('</span>, <span class="ruby-string">''</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-string">')'</span>, <span class="ruby-string">''</span>).<span class="ruby-identifier">to_f</span>
|
722
|
+
<span class="ruby-keyword">else</span>
|
723
|
+
<span class="ruby-value">0.0</span>
|
724
|
+
<span class="ruby-keyword">end</span>
|
725
|
+
<span class="ruby-keyword">end</span></pre>
|
726
|
+
</div>
|
727
|
+
|
728
|
+
</div>
|
729
|
+
|
730
|
+
|
731
|
+
|
732
|
+
|
733
|
+
</div>
|
734
|
+
|
735
|
+
|
736
|
+
<div id="method-i-process_free_member" class="method-detail ">
|
737
|
+
|
738
|
+
<div class="method-heading">
|
739
|
+
<span class="method-name">process_free_member</span><span
|
740
|
+
class="method-args">(line_equation, variable)</span>
|
741
|
+
|
742
|
+
<span class="method-click-advice">click to toggle source</span>
|
743
|
+
|
744
|
+
</div>
|
745
|
+
|
746
|
+
|
747
|
+
<div class="method-description">
|
748
|
+
|
749
|
+
|
750
|
+
|
751
|
+
|
752
|
+
|
753
|
+
|
754
|
+
<div class="method-source-code" id="process_free_member-source">
|
755
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 180</span>
|
756
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">process_free_member</span>(<span class="ruby-identifier">line_equation</span>, <span class="ruby-identifier">variable</span>)
|
757
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">variable</span>)
|
758
|
+
<span class="ruby-identifier">before</span> = <span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">variable</span>) <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
|
759
|
+
<span class="ruby-identifier">after</span> = <span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">index</span>(<span class="ruby-string">'/'</span>)
|
760
|
+
|
761
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">needed_variables_order?</span>(<span class="ruby-identifier">before</span>, <span class="ruby-identifier">after</span>)
|
762
|
+
<span class="ruby-identifier">throw</span> <span class="ruby-constant">VariablesOrderException</span>
|
763
|
+
<span class="ruby-keyword">end</span>
|
764
|
+
|
765
|
+
<span class="ruby-identifier">line_equation</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">before</span><span class="ruby-operator">..</span><span class="ruby-identifier">after</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-string">'/'</span>, <span class="ruby-string">''</span>).<span class="ruby-identifier">to_f</span> <span class="ruby-operator">*</span> (<span class="ruby-value">-1</span>)
|
766
|
+
<span class="ruby-keyword">else</span>
|
767
|
+
<span class="ruby-value">0.0</span>
|
768
|
+
<span class="ruby-keyword">end</span>
|
769
|
+
<span class="ruby-keyword">end</span></pre>
|
770
|
+
</div>
|
771
|
+
|
772
|
+
</div>
|
773
|
+
|
774
|
+
|
775
|
+
|
776
|
+
|
777
|
+
</div>
|
778
|
+
|
779
|
+
|
780
|
+
<div id="method-i-process_line_by_coordinates" class="method-detail ">
|
781
|
+
|
782
|
+
<div class="method-heading">
|
783
|
+
<span class="method-name">process_line_by_coordinates</span><span
|
784
|
+
class="method-args">(line_equation, func)</span>
|
785
|
+
|
786
|
+
<span class="method-click-advice">click to toggle source</span>
|
787
|
+
|
788
|
+
</div>
|
789
|
+
|
790
|
+
|
791
|
+
<div class="method-description">
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
|
796
|
+
|
797
|
+
|
798
|
+
<div class="method-source-code" id="process_line_by_coordinates-source">
|
799
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 151</span>
|
800
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">process_line_by_coordinates</span>(<span class="ruby-identifier">line_equation</span>, <span class="ruby-identifier">func</span>)
|
801
|
+
<span class="ruby-identifier">copy_line</span> = <span class="ruby-identifier">insert_eq</span>(<span class="ruby-identifier">line_equation</span>)
|
802
|
+
<span class="ruby-identifier">func</span> = <span class="ruby-identifier">method</span>(<span class="ruby-identifier">func</span>)
|
803
|
+
<span class="ruby-identifier">res</span> = []
|
804
|
+
<span class="ruby-identifier">res</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">func</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">copy_line</span>, <span class="ruby-string">'x'</span>)
|
805
|
+
<span class="ruby-identifier">copy_line</span> = <span class="ruby-identifier">cut_by_eq</span>(<span class="ruby-identifier">copy_line</span>)
|
806
|
+
<span class="ruby-identifier">res</span>[<span class="ruby-value">1</span>] = <span class="ruby-identifier">func</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">copy_line</span>, <span class="ruby-string">'y'</span>)
|
807
|
+
<span class="ruby-identifier">copy_line</span> = <span class="ruby-identifier">cut_by_eq</span>(<span class="ruby-identifier">copy_line</span>)
|
808
|
+
<span class="ruby-identifier">res</span>[<span class="ruby-value">2</span>] = <span class="ruby-identifier">func</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">copy_line</span>, <span class="ruby-string">'z'</span>)
|
809
|
+
<span class="ruby-identifier">res</span>
|
810
|
+
<span class="ruby-keyword">end</span></pre>
|
811
|
+
</div>
|
812
|
+
|
813
|
+
</div>
|
814
|
+
|
815
|
+
|
816
|
+
|
817
|
+
|
818
|
+
</div>
|
819
|
+
|
820
|
+
|
821
|
+
<div id="method-i-put_point_in_part" class="method-detail ">
|
822
|
+
|
823
|
+
<div class="method-heading">
|
824
|
+
<span class="method-name">put_point_in_part</span><span
|
825
|
+
class="method-args">(part, point, direction)</span>
|
826
|
+
|
827
|
+
<span class="method-click-advice">click to toggle source</span>
|
828
|
+
|
829
|
+
</div>
|
830
|
+
|
831
|
+
|
832
|
+
<div class="method-description">
|
833
|
+
|
834
|
+
|
835
|
+
|
836
|
+
|
837
|
+
|
838
|
+
|
839
|
+
<div class="method-source-code" id="put_point_in_part-source">
|
840
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 98</span>
|
841
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">put_point_in_part</span>(<span class="ruby-identifier">part</span>, <span class="ruby-identifier">point</span>, <span class="ruby-identifier">direction</span>)
|
842
|
+
<span class="ruby-identifier">direction</span> = <span class="ruby-identifier">method</span>(<span class="ruby-identifier">direction</span>)
|
843
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">part</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">>=</span> <span class="ruby-value">2</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">direction</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">part</span>[<span class="ruby-identifier">part</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">2</span>], <span class="ruby-identifier">part</span>[<span class="ruby-identifier">part</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>], <span class="ruby-identifier">point</span>)
|
844
|
+
<span class="ruby-identifier">part</span>.<span class="ruby-identifier">pop</span>
|
845
|
+
<span class="ruby-keyword">end</span>
|
846
|
+
<span class="ruby-identifier">part</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">point</span>)
|
847
|
+
<span class="ruby-keyword">end</span></pre>
|
848
|
+
</div>
|
849
|
+
|
850
|
+
</div>
|
851
|
+
|
852
|
+
|
853
|
+
|
854
|
+
|
855
|
+
</div>
|
856
|
+
|
857
|
+
|
858
|
+
<div id="method-i-vector_length" class="method-detail ">
|
859
|
+
|
860
|
+
<div class="method-heading">
|
861
|
+
<span class="method-name">vector_length</span><span
|
862
|
+
class="method-args">(vector)</span>
|
863
|
+
|
864
|
+
<span class="method-click-advice">click to toggle source</span>
|
865
|
+
|
866
|
+
</div>
|
867
|
+
|
868
|
+
|
869
|
+
<div class="method-description">
|
870
|
+
|
871
|
+
|
872
|
+
|
873
|
+
|
874
|
+
|
875
|
+
|
876
|
+
<div class="method-source-code" id="vector_length-source">
|
877
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 213</span>
|
878
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">vector_length</span>(<span class="ruby-identifier">vector</span>)
|
879
|
+
<span class="ruby-constant">Math</span>.<span class="ruby-identifier">sqrt</span>(<span class="ruby-identifier">vector</span>[<span class="ruby-value">0</span>]<span class="ruby-operator">**</span><span class="ruby-value">2</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">vector</span>[<span class="ruby-value">1</span>]<span class="ruby-operator">**</span><span class="ruby-value">2</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">vector</span>[<span class="ruby-value">2</span>]<span class="ruby-operator">**</span><span class="ruby-value">2</span>)
|
880
|
+
<span class="ruby-keyword">end</span></pre>
|
881
|
+
</div>
|
882
|
+
|
883
|
+
</div>
|
884
|
+
|
885
|
+
|
886
|
+
|
887
|
+
|
888
|
+
</div>
|
889
|
+
|
890
|
+
|
891
|
+
<div id="method-i-vectors_product" class="method-detail ">
|
892
|
+
|
893
|
+
<div class="method-heading">
|
894
|
+
<span class="method-name">vectors_product</span><span
|
895
|
+
class="method-args">(v1, v2)</span>
|
896
|
+
|
897
|
+
<span class="method-click-advice">click to toggle source</span>
|
898
|
+
|
899
|
+
</div>
|
900
|
+
|
901
|
+
|
902
|
+
<div class="method-description">
|
903
|
+
|
904
|
+
|
905
|
+
|
906
|
+
|
907
|
+
|
908
|
+
|
909
|
+
<div class="method-source-code" id="vectors_product-source">
|
910
|
+
<pre><span class="ruby-comment"># File lib/geometry.rb, line 205</span>
|
911
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">vectors_product</span>(<span class="ruby-identifier">v1</span>, <span class="ruby-identifier">v2</span>)
|
912
|
+
<span class="ruby-identifier">res</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">3</span>)
|
913
|
+
(<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
914
|
+
<span class="ruby-identifier">res</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">v1</span>[(<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>) <span class="ruby-operator">%</span> <span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">v2</span>[(<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>) <span class="ruby-operator">%</span> <span class="ruby-value">3</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">v1</span>[(<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>) <span class="ruby-operator">%</span> <span class="ruby-value">3</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">v2</span>[(<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>) <span class="ruby-operator">%</span> <span class="ruby-value">3</span>]
|
915
|
+
<span class="ruby-keyword">end</span>
|
916
|
+
<span class="ruby-identifier">res</span>
|
917
|
+
<span class="ruby-keyword">end</span></pre>
|
918
|
+
</div>
|
919
|
+
|
920
|
+
</div>
|
921
|
+
|
922
|
+
|
923
|
+
|
924
|
+
|
925
|
+
</div>
|
926
|
+
|
927
|
+
|
928
|
+
</section>
|
929
|
+
|
930
|
+
</section>
|
931
|
+
|
932
|
+
</main>
|
933
|
+
|
934
|
+
|
935
|
+
<footer id="validator-badges" role="contentinfo">
|
936
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
937
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.0.
|
938
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
939
|
+
</footer>
|
940
|
+
|