module Geom

Parent: N/A | Class Index
Methods:closest_points, fit_plane_to_points, intersect_line_line, intersect_line_plane, intersect_plane_plane, linear_combination, point_in_polygon_2d |
Sample Code:GeomTests.rb |

The Geom module defines a number of Module methods that let you perform different geometric operations.
The methods in this module take lines and planes as arguments. There is no special class for representing lines or planes.
A line can be represented as either an Array of a point and a vector, or as an Array of two points.
line = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
line = [Geom::Point3d.new(0,0,0), Geom::Point3d.new(0,0,100)]
A plane can be represented as either an Array of a point and a vector, or as an Array of 4 numbers that given the coeficients of a plane equation.
plane = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
plane = [0,0,1,0]
NOTE: Lines and Planes are infinite.
There are several good books on 3D math if you are new to the concepts of a line, plane, and vector.

Module Methods

closest_points
The closest_points method is used to compute the closest points on two lines.
Syntax:
pts = Geom.closest_points line1, line2
Arguments:
Return Value:
pts - an array of two points. The first point is on the first line and the second point is on the second line.
Comments:
Example:
line1 = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)] line2 = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,100)] # 0,0,0 on each line should be closest because both lines start from # that point pts = Geom.closest_points line1, line2

fit_plane_to_points
The fit_plane_to_points method is used to compute a plane that is a best fit to an array of points
Syntax:
plane = Geom.fit_plane_to_points points plane = Geom.fit_plane_to_points point1, point2, point3, ...
Arguments:
points - an array of points point1, point2, point3 - Point3D objects
Return Value:
plane - a plane
Comments:
If more than three points are given, some of the points may not be on the plane. The plane is returned as an Array of 4 numbers which are the coefficients of the plane equation Ax + By + Cz + D = 0
Example:
point1 = Geom::Point3d.new 0,0,0 point2 = Geom::Point3d.new 10,10,10 point3 = Geom::Point3d.new 25,25,25 plane = Geom.fit_plane_to_points point1, point2, point3

intersect_line_line
The intersect_line_line computes the intersection of two lines.
Syntax:
point = Geom.intersect_line_line line1, line2
Arguments:
line1, line2 - A line is given as either an array of a point and a vector, or an Array or two points.
Return Value:
Returns nil if they do not intersect.
Comments:
Example:
line1=[Geom::Point3d.new(10,0,0),Geom::Vector3d.new(1,0,0)] line2=[Geom::Point3d.new(0,10,0),Geom::Point3d.new(20,10,0)] pt = Geom.intersect_line_line(line1, line2) This will return the point (10,10,0).

intersect_line_plane
The intersect_line_plane method is used to compute the intersection of a line and a plane.
Syntax:
point = Geom.intersect_line_plane line, plane
Arguments:
line - a line plane - a plane
Return Value:
point - a Point3d object
Comments:
Example:
# This is really the normal which follows the x axis. The plane is # perpendicular plane1 = [Geom::Point3d.new(-10, 0 ,0), Geom::Vector3d.new(1,0,0)] # This line follows the x axis line1 = [Geom::Point3d.new(-10,0,0), Geom::Vector3d.new(1,0,0)] # returns -10, 0, 0 pt = Geom.intersect_line_plane(line1, plane1)

intersect_plane_plane
The intersect_plane_plane method is used to compute the intersection of two planes.
Syntax:
line = Geom.intersect_plane_plane plane1, plane2
Arguments:
plane1, plane2 - planes
Return Value:
line - a line where the planes intersect if successful. Returns nil if the planes do not intersect.
Comments:
Example:
# This is really the normal which follows the x axis. The plane is # perpendicular (or parallel to the Y axis) plane1 = [Geom::Point3d.new(-10, 0 ,0), Geom::Vector3d.new(1,0,0)] # This is really the normal which follows the y axis. The plane is # perpendicular (or parallel to the X axis) plane2 = [Geom::Point3d.new(0,-10,0), Geom::Vector3d.new(0,1,0)] # returns (-10,-10,0")(0.0,0.0,1.0) line = Geom.intersect_plane_plane(plane1, plane2)

linear_combination
The linear_combination method is used to compute the linear combination of points or vectors.
Syntax:
point = Geom.linear_combination(weight1, point1, weight2, point2) vector = Geom.linear_combination(weight1, vector1, weight2, vector2)
Arguments:
weight1 - a weight or percentage point1 - the start point on the line weight2 - a weight or percentage point2 - the end point of the line vector1 - the first vector vector2 - the end point of the line
Return Value:
point - point - a Point3d object vector - vector - a Vector3d object
Comments:
Example:
point1 = Geom::Point3d.new 1,1,1 point2 = Geom::Point3d.new 10,10,10 # Gets the point on the line segment connecting point1 and point2 that is # 3/4 the way from point1 to point2. point = Geom.linear_combination 0.25, point1, 0.75, point2

point_in_polygon_2D
The point_to_polygon_2D method is used to determine whether a point is inside a polygon when that point is projected as though it and the polygon were in 2D space. The Z component is ignored.
Syntax:
status = Geom.point_to_polygon_2D point, points,
Arguments:
point - a Point3d object points - an array of points that represent the points of the polygon you are checking border - true if a point on the border is counted as inside the polygon.
Return Value:
status - true if the point is inside the polygon. False if the point is not inside the polygon.
Comments:
Example: