Class: Topolys::Point3D

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(x, y, z) ⇒ Point3D

Initializes a Point3D object

Parameters:

  • X-coordinate (Float)
  • Y-coordinate (Float)
  • Z-coordinate (Float)


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

#xFloat (readonly)

Returns X, Y, or Z coordinate.

Returns:

  • (Float)

    X, Y, or Z coordinate



9
10
11
# File 'lib/topolys/geometry.rb', line 9

def x
  @x
end

#yFloat (readonly)

Returns X, Y, or Z coordinate.

Returns:

  • (Float)

    X, Y, or Z coordinate



9
10
11
# File 'lib/topolys/geometry.rb', line 9

def y
  @y
end

#zFloat (readonly)

Returns X, Y, or Z coordinate.

Returns:

  • (Float)

    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

Parameters:

Returns:

  • (Point3D)

    Returns a new Point3D - nil if vector not a Vector3D



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

Parameters:

  • other (Point3D)

    Another 3D point

Returns:

  • (Vector3D)

    Returns a new Vector3D - nil if other not a Point3D



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_sObject



26
27
28
# File 'lib/topolys/geometry.rb', line 26

def to_s
  "[#{@x}, #{@y}, #{@z}]"
end