Class: Topolys::Point3D
- Inherits:
-
Object
- Object
- Topolys::Point3D
- Defined in:
- lib/topolys/geometry.rb
Overview
Point3D, Vector3D, and Plane3D represents the 3D position and orientation of geometry in Topolys. Geometry is separate from topology (connections).
Instance Attribute Summary collapse
-
#x ⇒ Float
readonly
X, Y, or Z coordinate.
-
#y ⇒ Float
readonly
X, Y, or Z coordinate.
-
#z ⇒ Float
readonly
X, Y, or Z coordinate.
Instance Method Summary collapse
-
#+(vector) ⇒ Point3D
Adds a 3D vector to self.
-
#-(other) ⇒ Vector3D
Generates a 3D vector which goes from other to self.
-
#initialize(x, y, z) ⇒ Point3D
constructor
Initializes a Point3D object.
- #to_s ⇒ Object
Constructor Details
#initialize(x, y, z) ⇒ Point3D
Initializes a Point3D object
17 18 19 20 21 22 23 24 |
# File 'lib/topolys/geometry.rb', line 17 def initialize(x, y, z) raise "Incorrect x argument for Point3D, expected Numeric but got #{x.class}" unless x.is_a?(Numeric) raise "Incorrect y argument for Point3D, expected Numeric but got #{y.class}" unless y.is_a?(Numeric) raise "Incorrect z argument for Point3D, expected Numeric but got #{z.class}" unless z.is_a?(Numeric) @x = x @y = y @z = z end |
Instance Attribute Details
#x ⇒ Float (readonly)
Returns X, Y, or Z coordinate.
9 10 11 |
# File 'lib/topolys/geometry.rb', line 9 def x @x end |
#y ⇒ Float (readonly)
Returns X, Y, or Z coordinate.
9 10 11 |
# File 'lib/topolys/geometry.rb', line 9 def y @y end |
#z ⇒ Float (readonly)
Returns X, Y, or Z coordinate.
9 10 11 |
# File 'lib/topolys/geometry.rb', line 9 def z @z end |
Instance Method Details
#+(vector) ⇒ Point3D
Adds a 3D vector to self
36 37 38 39 40 41 42 |
# File 'lib/topolys/geometry.rb', line 36 def +(vector) return nil unless vector.is_a?(Topolys::Vector3D) x = @x + vector.x y = @y + vector.y z = @z + vector.z return Topolys::Point3D.new(x, y, z) end |
#-(other) ⇒ Vector3D
Generates a 3D vector which goes from other to self
50 51 52 53 54 55 56 |
# File 'lib/topolys/geometry.rb', line 50 def -(other) return nil unless other.is_a?(Topolys::Point3D) x = @x - other.x y = @y - other.y z = @z - other.z return Topolys::Vector3D.new(x, y, z) end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/topolys/geometry.rb', line 26 def to_s "[#{@x}, #{@y}, #{@z}]" end |