Class: Geom::RectangularCoordinateSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/geom/rectangular_coordinate_system.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRectangularCoordinateSystem

Returns a new instance of RectangularCoordinateSystem.



5
6
7
8
9
10
# File 'lib/geom/rectangular_coordinate_system.rb', line 5

def initialize
  @origin = Point.new(0.0, 0.0, 0.0)
  @x_vector = Vector.new(1.0, 0.0, 0.0)
  @y_vector = Vector.new(0.0, 1.0, 0.0)
  @z_vector = Vector.new(0.0, 0.0, 1.0)
end

Instance Attribute Details

#originObject

Returns the value of attribute origin.



3
4
5
# File 'lib/geom/rectangular_coordinate_system.rb', line 3

def origin
  @origin
end

#x_vectorObject

Returns the value of attribute x_vector.



3
4
5
# File 'lib/geom/rectangular_coordinate_system.rb', line 3

def x_vector
  @x_vector
end

#y_vectorObject

Returns the value of attribute y_vector.



3
4
5
# File 'lib/geom/rectangular_coordinate_system.rb', line 3

def y_vector
  @y_vector
end

#z_vectorObject

Returns the value of attribute z_vector.



3
4
5
# File 'lib/geom/rectangular_coordinate_system.rb', line 3

def z_vector
  @z_vector
end

Class Method Details

.new_from_xvector_and_xyplane(origin, axis_vector, plane_vector) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/geom/rectangular_coordinate_system.rb', line 12

def self.new_from_xvector_and_xyplane(origin, axis_vector, plane_vector)
  rcs = self.new
  rcs.origin = origin
  rcs.x_vector = axis_vector.unitize
  rcs.z_vector = plane_vector.unitize
  rcs.y_vector = rcs.z_vector.cross(rcs.x_vector).unitize
  rcs.z_vector = rcs.x_vector.cross(rcs.y_vector).unitize
  rcs
end

.new_from_yvector_and_yzplane(origin, axis_vector, plane_vector) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/geom/rectangular_coordinate_system.rb', line 22

def self.new_from_yvector_and_yzplane(origin, axis_vector, plane_vector)
  rcs = self.new
  rcs.origin = origin
  rcs.y_vector = axis_vector.unitize
  rcs.x_vector = plane_vector.unitize
  rcs.z_vector = rcs.x_vector.cross(rcs.y_vector).unitize
  rcs.x_vector = rcs.y_vector.cross(rcs.z_vector).unitize
  rcs
end

.new_from_zvector_and_zxplane(origin, axis_vector, plane_vector) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/geom/rectangular_coordinate_system.rb', line 32

def self.new_from_zvector_and_zxplane(origin, axis_vector, plane_vector)
  rcs = self.new
  rcs.origin = origin
  rcs.z_vector = axis_vector.unitize
  rcs.y_vector = plane_vector.unitize
  rcs.x_vector = rcs.y_vector.cross(rcs.z_vector).unitize
  rcs.y_vector = rcs.z_vector.cross(rcs.x_vector).unitize
  rcs
end

Instance Method Details

#==(rcs) ⇒ Object Also known as: eql?



64
65
66
67
68
69
# File 'lib/geom/rectangular_coordinate_system.rb', line 64

def == rcs
  rcs.x_vector == @x_vector &&
  rcs.y_vector == @y_vector &&
  rcs.z_vector == @z_vector &&
  rcs.origin == @origin
end

#hashObject



73
74
75
# File 'lib/geom/rectangular_coordinate_system.rb', line 73

def hash
  (@x_vector.hash ^ @y_vector.hash ^ @z_vector.hash ^ @origin.hash)
end

#to_s(verbose = false) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/geom/rectangular_coordinate_system.rb', line 51

def to_s(verbose=false)
  unless verbose
    "RCS[#{@origin.to_s} X-#{@x_vector.to_s} Y-#{@y_vector.to_s} Z-#{@z_vector.to_s}]"
  else
    str = "Rectangular Coordinate System\n"
    str += "Origin:    #{@origin.to_s}\n"
    str += "X-Vector: #{@x_vector.to_s}\n"
    str += "Y-Vector: #{@y_vector.to_s}\n"
    str += "Z-Vector: #{@z_vector.to_s}"
    str
  end
end

#transformation_matrixObject



42
43
44
45
46
47
48
49
# File 'lib/geom/rectangular_coordinate_system.rb', line 42

def transformation_matrix
  Matrix[
    [@x_vector.x, @y_vector.x, @z_vector.x, @origin.x],
    [@x_vector.y, @y_vector.y, @z_vector.y, @origin.y],
    [@x_vector.z, @y_vector.z, @z_vector.z, @origin.z],
    [0.0, 0.0, 0.0, 1.0]
  ]
end