Class: Geo3d::Triangle
- Inherits:
-
Object
- Object
- Geo3d::Triangle
- Defined in:
- lib/geo3d/triangle.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#c ⇒ Object
Returns the value of attribute c.
Instance Method Summary collapse
- #clockwise?(reference_normal = Vector.new(0,0,-1)) ⇒ Boolean (also: #cw?)
- #counter_clockwise?(reference_normal = Vector.new(0,0,-1)) ⇒ Boolean (also: #ccw?)
- #flip ⇒ Object
- #flip! ⇒ Object
-
#initialize(*args) ⇒ Triangle
constructor
A new instance of Triangle.
- #normal ⇒ Object
- #points ⇒ Object
- #signed_area(reference_normal = Vector.new(0,0,-1)) ⇒ Object
Constructor Details
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
3 4 5 |
# File 'lib/geo3d/triangle.rb', line 3 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
3 4 5 |
# File 'lib/geo3d/triangle.rb', line 3 def b @b end |
#c ⇒ Object
Returns the value of attribute c.
3 4 5 |
# File 'lib/geo3d/triangle.rb', line 3 def c @c end |
Instance Method Details
#clockwise?(reference_normal = Vector.new(0,0,-1)) ⇒ Boolean Also known as: cw?
38 39 40 |
# File 'lib/geo3d/triangle.rb', line 38 def clockwise? reference_normal = Vector.new(0,0,-1) signed_area( reference_normal ) > 0 end |
#counter_clockwise?(reference_normal = Vector.new(0,0,-1)) ⇒ Boolean Also known as: ccw?
42 43 44 |
# File 'lib/geo3d/triangle.rb', line 42 def counter_clockwise? reference_normal = Vector.new(0,0,-1) signed_area( reference_normal ) < 0 end |
#flip ⇒ Object
19 20 21 22 23 |
# File 'lib/geo3d/triangle.rb', line 19 def flip f = clone f.flip! f end |
#flip! ⇒ Object
15 16 17 |
# File 'lib/geo3d/triangle.rb', line 15 def flip! @b, @c = @c, @b end |
#normal ⇒ Object
25 26 27 |
# File 'lib/geo3d/triangle.rb', line 25 def normal (b - a).cross(c - a).normalize end |
#points ⇒ Object
5 6 7 |
# File 'lib/geo3d/triangle.rb', line 5 def points [a, b, c] end |
#signed_area(reference_normal = Vector.new(0,0,-1)) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/geo3d/triangle.rb', line 29 def signed_area reference_normal = Vector.new(0,0,-1) sum = Vector.new 0, 0, 0, 0 points.each_with_index do |current_point, i| next_point = points[(i == points.size - 1) ? 0 : i+1] sum += current_point.cross next_point end reference_normal.dot(sum) / 2.0 end |