Class: Geom::Edge
- Inherits:
-
Object
- Object
- Geom::Edge
- Defined in:
- lib/geom/edge.rb
Instance Attribute Summary collapse
-
#end_point ⇒ Object
Returns the value of attribute end_point.
-
#start_point ⇒ Object
Returns the value of attribute start_point.
Instance Method Summary collapse
- #clone ⇒ Object
- #direction ⇒ Object
- #extrude(distance, direction) ⇒ Object
-
#initialize(sp, ep) ⇒ Edge
constructor
A new instance of Edge.
- #length ⇒ Object
- #offset(distance, up) ⇒ Object
- #snap(point) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(sp, ep) ⇒ Edge
Returns a new instance of Edge.
4 5 6 7 |
# File 'lib/geom/edge.rb', line 4 def initialize(sp,ep) @start_point = sp @end_point = ep end |
Instance Attribute Details
#end_point ⇒ Object
Returns the value of attribute end_point.
3 4 5 |
# File 'lib/geom/edge.rb', line 3 def end_point @end_point end |
#start_point ⇒ Object
Returns the value of attribute start_point.
3 4 5 |
# File 'lib/geom/edge.rb', line 3 def start_point @start_point end |
Instance Method Details
#clone ⇒ Object
81 82 83 |
# File 'lib/geom/edge.rb', line 81 def clone Edge.new(@start_point.clone,@end_point.clone) end |
#direction ⇒ Object
9 10 11 |
# File 'lib/geom/edge.rb', line 9 def direction Number3D.sub(@start_point.position,@end_point.position) end |
#extrude(distance, direction) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/geom/edge.rb', line 42 def extrude(distance,direction) edge = clone [edge.start_point,edge.end_point].each do |v| v.x += distance*direction.x v.y += distance*direction.y v.z += distance*direction.z end poly = Polygon.new poly.vertices.push( edge.end_point , edge.start_point, @start_point , @end_point) poly end |
#length ⇒ Object
13 14 15 16 17 18 |
# File 'lib/geom/edge.rb', line 13 def length x = @end_point.x - @start_point.x; y = @end_point.y - @start_point.y; z = @end_point.z - @start_point.z; Math.sqrt(x*x + y*y + z*z); end |
#offset(distance, up) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/geom/edge.rb', line 20 def offset(distance,up) up.normalize edge = clone dir = direction Matrix3D.multiply_vector_3x3(Matrix3D.rotation(up.x,up.y,up.z, -Math::PI/2),dir) dir.normalize dir.x *= distance dir.y *= distance dir.z *= distance edge.start_point.x += dir.x edge.start_point.y += dir.y edge.start_point.z += dir.z edge.end_point.x += dir.x edge.end_point.y += dir.y edge.end_point.z += dir.z edge end |
#snap(point) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/geom/edge.rb', line 57 def snap(point) x1 = @start_point.x y1 = @start_point.y z1 = @start_point.z x2 = @end_point.x y2 = @end_point.y z2 = @end_point.z x3 = point.x y3 = point.y z3 = point.z dx = x2-x1 dy = y2-y1 dz = z2-z1 if dx == 0 && dy == 0 && dz == 0 return @start_point else t = ((x3 - x1) * dx + (y3 - y1) * dy + (z3 - z1) * dz) / (dx**2 + dy**2 + dz**2) x0 = x1 + t * dx y0 = y1 + t * dy z0 = z1 + t * dz return Vertex.new(x0,y0,z0) end end |
#to_s ⇒ Object
85 86 87 |
# File 'lib/geom/edge.rb', line 85 def to_s "#<Geom::Edge:#{@start_point.to_s},#{@end_point.to_s}>" end |