Module: GridGenerator::Helper
- Defined in:
- lib/grid_generator/helper.rb
Class Method Summary collapse
- .distance(a, b) ⇒ Object
- .intersection(ab, cd) ⇒ Object
-
.intervals(a, b, i) ⇒ Object
1 -> / 2 | 2 -> / 3 |.
Class Method Details
.distance(a, b) ⇒ Object
3 4 5 |
# File 'lib/grid_generator/helper.rb', line 3 def self.distance(a, b) Math.sqrt((b[0,0] - a[0,0])**2 + (b[1,0] - a[1,0])**2) end |
.intersection(ab, cd) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/grid_generator/helper.rb', line 22 def self.intersection(ab,cd) x1 = ab.a[0,0] y1 = ab.a[1,0] x2 = ab.b[0,0] y2 = ab.b[1,0] x3 = cd.a[0,0] y3 = cd.a[1,0] x4 = cd.b[0,0] y4 = cd.b[1,0] px_numerator = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4) px_denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4) py_numerator = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4) py_denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4) px = px_numerator.to_f / px_denominator py = py_numerator.to_f / py_denominator Matrix.column_vector([px, py]) end |
.intervals(a, b, i) ⇒ Object
1 -> / 2 | 2 -> / 3 |
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/grid_generator/helper.rb', line 9 def self.intervals(a, b, i) dx = b[0,0] - a[0,0] dy = b[1,0] - a[1,0] Array.new(i) do |n| interval_x = dx / (i + 1) interval_y = dy / (i + 1) x = a[0,0] + (n + 1) * interval_x y = a[1,0] + (n + 1) * interval_y Matrix.column_vector([x, y]) end end |