class Silicium::Geometry3d::Plane3d
Class represents a plane as equation Ax + By + Cz+D = 0 in two-dimensional space
Attributes
free_coefficient[R]
x_coefficient[R]
y_coefficient[R]
z_coefficient[R]
Public Class Methods
new(point1, point2, point3)
click to toggle source
Initializes with three objects of type Point
# File lib/geometry3d.rb, line 29 def initialize(point1, point2, point3) vector1 = Vector3d.new(point1) norm = vector1.norm_vector(point2, point3) @x_coefficient = norm.x @y_coefficient = norm.y @z_coefficient = norm.z @free_coefficient = -point1.x * norm.x + (-point1.y * norm.y) + (-point1.z * norm.z) end
Public Instance Methods
distance_between_parallel_planes(other_plane)
click to toggle source
The distance between parallel planes
# File lib/geometry3d.rb, line 90 def distance_between_parallel_planes(other_plane) raise 'Planes are not parallel' if !parallel?(other_plane) free = (other_plane.free_coefficient - @free_coefficient).abs free / sqrt(@x_coefficient**2 + @y_coefficient**2 + @z_coefficient**2) end
distance_point_to_plane(point)
click to toggle source
The distance from a point to a plane
# File lib/geometry3d.rb, line 100 def distance_point_to_plane(point) norm = 1 / Math.sqrt(@x_coefficient**2 + @y_coefficient**2 + @z_coefficient**2) (@x_coefficient * norm * point.x + @y_coefficient * norm * point.y + @z_coefficient * norm * point.z + @free_coefficient * norm).abs end
initialize_with_coefficients(a, b, c, d)
click to toggle source
Initializes with coefficients
# File lib/geometry3d.rb, line 40 def initialize_with_coefficients(a, b, c, d) raise ArgumentError, 'All coefficients cannot be 0 ' if a.equal?(0) && b.equal?(0) && c.equal?(0) && (d.equal?(0) || !d.equal?(0)) @x_coefficient = a @y_coefficient = b @z_coefficient = c @free_coefficient = d end
intersecting?(other_plane)
click to toggle source
Checks if two planes are intersecting in 3-dimensional space
# File lib/geometry3d.rb, line 72 def intersecting?(other_plane) check_x = @x_coefficient != other_plane.x_coefficient check_y = @y_coefficient != other_plane.y_coefficient check_z = @z_coefficient != other_plane.z_coefficient check_x || check_y || check_z end
parallel?(other_plane)
click to toggle source
Checks if two planes are parallel in 3-dimensional space
# File lib/geometry3d.rb, line 64 def parallel?(other_plane) v1 = Vector3d.new(Point3d.new(@x_coefficient, @y_coefficient, @z_coefficient)) v2 = Vector3d.new(Point3d.new(other_plane.x_coefficient, other_plane.y_coefficient, other_plane.z_coefficient)) v1.collinear?(v2) end
perpendicular?(other_plane)
click to toggle source
Checks if two planes are perpendicular
# File lib/geometry3d.rb, line 81 def perpendicular?(other_plane) check_x = @x_coefficient * other_plane.x_coefficient check_y = @y_coefficient * other_plane.y_coefficient check_z = @z_coefficient * other_plane.z_coefficient (check_x + check_y + check_z).equal?(0) end
point_is_on_line?(point1, point2, point3)
click to toggle source
check if the points isn't on the same line
# File lib/geometry3d.rb, line 51 def point_is_on_line?(point1, point2, point3) check_p1 = @x_coefficient * point1.x + @y_coefficient * point1.y + @z_coefficient * point1.z + @free_coefficient check_p2 = @x_coefficient * point2.x + @y_coefficient * point2.y + @z_coefficient * point2.z + @free_coefficient check_p3 = @x_coefficient * point3.x + @y_coefficient * point3.y + @z_coefficient * point3.z + @free_coefficient check_p1.equal?(0) && check_p2.equal?(0) && check_p3.equal?(0) end
point_is_on_plane?(point)
click to toggle source
check if the point isn't on the plane
# File lib/geometry3d.rb, line 59 def point_is_on_plane?(point) (@x_coefficient * point.x + @y_coefficient * point.y + @z_coefficient * point.z + @free_coefficient).equal?(0) end