Module: Silicium::Geometry3d

Defined in:
lib/geometry3d.rb

Defined Under Namespace

Classes: Plane3d, Point3d, Vector3d

Instance Method Summary collapse

Instance Method Details

#directing_vector3d(line_equation) ⇒ Object

Creates an array- directing vector in three-dimensional space . The equation is specified in the canonical form. Example, (x-0) / 26 = (y + 300) / * (- 15) = (z-200) / 51

Important: mandatory order of variables: x, y, z



241
242
243
# File 'lib/geometry3d.rb', line 241

def directing_vector3d(line_equation)
  process_line_by_coordinates(line_equation, :process_cf)
end

#distance_point_to_point3d(a, b) ⇒ Object

Calculates the distance from given points in three-dimensional space



15
16
17
# File 'lib/geometry3d.rb', line 15

def distance_point_to_point3d(a, b)
  Math.sqrt((b.x - a.x)**2 + (b.y - a.y)**2 + (b.z - a.z)**2)
end

#height_point_3d(line_equation) ⇒ Object

Creates an array of coordinates of the point ([x, y, z] on the line given by the equation in the canonical form. Example, (x-0) / 26 = (y + 300) / * (- 15) = (z-200) / 51

Important: mandatory order of variables: x, y, z



251
252
253
# File 'lib/geometry3d.rb', line 251

def height_point_3d(line_equation)
  process_line_by_coordinates(line_equation, :process_free_member)
end

#point_to_line_distance_3d(point, line_eq) ⇒ Object

Calculates the distance from a point given by a Point3d structure to a straight line given by a canonical equation. Example, (x-0) / 26 = (y + 300) / * (- 15) = (z-200) / 51

Important: mandatory order of variables: x, y, z



261
262
263
264
265
266
267
268
# File 'lib/geometry3d.rb', line 261

def point_to_line_distance_3d(point, line_eq)
  dir_vector = directing_vector3d(line_eq)
  line_point = height_point_3d(line_eq)
  height_vector = [line_point[0] - point.x, line_point[1] - point.y, line_point[2] - point.z]

  height_on_dir = vectors_product(height_vector, dir_vector)
  vector_length(height_on_dir) / vector_length(dir_vector)
end