Class: Topolys::Plane3D

Inherits:
Object
  • Object
show all
Defined in:
lib/topolys/geometry.rb

Overview

Vector3D

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(point, normal) ⇒ Plane3D

Initializes a Plane3D object from a point and an outward normal

Parameters:



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/topolys/geometry.rb', line 250

def initialize(point, normal)
  raise "Incorrect point argument for Plane3D, expected Point3D but got #{point.class}" unless point.is_a?(Topolys::Point3D)
  raise "Incorrect normal argument for Plane3D, expected Vector3D but got #{normal.class}" unless normal.is_a?(Topolys::Vector3D)
  raise "Incorrect normal argument for Plane3D, magnitude too small" unless normal.magnitude > Float::EPSILON

  @point = Point3D.new(point.x, point.y, point.z)
  @normal = Vector3D.new(normal.x, normal.y, normal.z)
  @normal.normalize!

  # coefficients for equation of a plane
  @a = @normal.x
  @b = @normal.y
  @c = @normal.z
  @d = -(@a*@point.x + @b*@point.y + @c*@point.z)
end

Instance Attribute Details

#normalVector3D (readonly)

Returns normalized vector perpendicular to plane.

Returns:

  • (Vector3D)

    normalized vector perpendicular to plane



243
244
245
# File 'lib/topolys/geometry.rb', line 243

def normal
  @normal
end

#pointPoint3D (readonly)

Returns arbitrary point on plane.

Returns:

  • (Point3D)

    arbitrary point on plane



240
241
242
# File 'lib/topolys/geometry.rb', line 240

def point
  @point
end

Class Method Details

.from_point_axes(point, xaxis, yaxis) ⇒ Object

Initializes a Plane3D object from a point and two vectors

Parameters:



293
294
295
296
297
298
299
300
301
302
# File 'lib/topolys/geometry.rb', line 293

def Plane3D.from_point_axes(point, xaxis, yaxis)
  return nil unless point.is_a?(Topolys::Point3D)
  return nil unless xaxis.is_a?(Topolys::Vector3D)
  return nil unless yaxis.is_a?(Topolys::Vector3D)

  normal = xaxis.cross(yaxis)
  return nil unless normal.magnitude > Float::EPSILON

  return Plane3D.new(point, normal)
end

.from_points(point1, point2, point3) ⇒ Object

Initializes a Plane3D object from three non-colinear points

Parameters:

  • point1 (Point3d)
  • point2 (Point3d)
  • point3 (Point3d)


276
277
278
279
280
281
282
283
284
285
# File 'lib/topolys/geometry.rb', line 276

def Plane3D.from_points(point1, point2, point3)
  return nil unless point1.is_a?(Topolys::Point3D)
  return nil unless point2.is_a?(Topolys::Point3D)
  return nil unless point3.is_a?(Topolys::Point3D)

  normal = (point2-point1).cross(point3-point1)
  return nil unless normal.magnitude > Float::EPSILON

  return Plane3D.new(point1, normal)
end

Instance Method Details

#project(point) ⇒ Point3d

Project a Point3d to this plane

Parameters:

  • point (Point3d)

Returns:

  • (Point3d)

    Returns point projected to this plane



312
313
314
315
# File 'lib/topolys/geometry.rb', line 312

def project(point)
  dist = @normal.dot(point-@point)
  return point + normal*(-dist)
end

#to_sObject



266
267
268
# File 'lib/topolys/geometry.rb', line 266

def to_s
  "[#{@a}, #{@b}, #{@c}, #{@d}]"
end