ModraUp Ruby API Documentation Ruby API Reference

Module: Geom

Overview

Geometry classes include Geom::Point3d, Geom::Point2d, Geom::Vector3d, Geom::BoundingBox, Geom::Bounds2d, Geom::Transformation, and Geom::PolygonMesh. The module also exposes line and plane tests, Geom::ORIGIN, Geom::X_AXIS, Geom::Y_AXIS, Geom::Z_AXIS, and Geom::IDENTITY. Represent a line as [point, vector] or [point, point]. Represent a plane as [point, normal] or four coefficients [A, B, C, D] for the equation Ax + By + Cz + D = 0.

Examples:

pt = Geom::Point3d.new(1, 2, 3)
pt.distance(Geom::ORIGIN)
Geom.intersect_line_line(
  [Geom::Point3d.new(20, 0, 0), Geom::Vector3d.new(0, 1, 0)],
  [Geom::Point3d.new(0, 10, 0), Geom::Point3d.new(20, 10, 0)])

Defined Under Namespace

Classes: BoundingBox, Bounds2d, Point2d, Point3d, PolygonMesh, Transformation, Vector3d

Constants # collapse

Geom::ORIGIN

ORIGIN = Geom::Point3d.new(0, 0, 0)

The model origin.

Returns:

  • (Geom::Point3d)

Examples:

Geom::ORIGIN.to_a  #=> [0.0, 0.0, 0.0]
Geom::X_AXIS

X_AXIS = Geom::Vector3d.new(1, 0, 0)

The World X-axis.

Returns:

  • (Geom::Vector3d)

Examples:

Geom::X_AXIS.to_a  #=> [1.0, 0.0, 0.0]
Geom::Y_AXIS

Y_AXIS = Geom::Vector3d.new(0, 1, 0)

World Y-axis.

Returns:

  • (Geom::Vector3d)

Examples:

Geom::Y_AXIS.to_a  #=> [0.0, 1.0, 0.0]
Geom::Z_AXIS

Z_AXIS = Geom::Vector3d.new(0, 0, 1)

The World Z-axis.

Returns:

  • (Geom::Vector3d)

Examples:

Geom::Z_AXIS.to_a  #=> [0.0, 0.0, 1.0]
Geom::IDENTITY

IDENTITY = Geom::Transformation.new

Unit transformation.

Returns:

  • (Geom::Transformation)

Examples:

Geom::IDENTITY.identity?

Class Method Summary # collapse

Class Method Details

Geom.closest_points(line1, line2) ⇒ Array(Geom::Point3d, Geom::Point3d)

The closest pair of points on two infinite lines. The first point is on line1.

Parameters:

  • line1 (Array) [point, vector] or[point, point]
  • line2 (Array)

Returns:

  • (Array<Geom::Point3d>)

Examples:

line1 = [Geom::Point3d.new(0, 2, 0), Geom::Vector3d.new(1, 0, 0)]
line2 = [Geom::Point3d.new(3, 0, 0), Geom::Vector3d.new(0, 1, 0)]
Geom.closest_points(line1, line2)[0].to_a  #=> [3.0, 2.0, 0.0]

Geom.fit_plane_to_points(point1, point2, point3, ...) ⇒ Array(Float, Float, Float, Float)Geom.fit_plane_to_points(points) ⇒ Array(Float, Float, Float, Float)

Fit a plane to a set of points and return the coefficients for the equation Ax + By + Cz + D = 0. Allow for some points to not lie on the plane when more than three points are provided.

Parameters:

  • point1 (Geom::Point3d, Array<Geom::Point3d>)

Returns:

  • (Array<Float>)

Raises:

  • [ArgumentError] Less than three points, or plane normal cannot be determined.

Examples:

plane = Geom.fit_plane_to_points(
  Geom::Point3d.new(0, 0, 0),
  Geom::Point3d.new(1, 0, 0),
  Geom::Point3d.new(0, 1, 0))
plane.length  #=> 4

Geom.intersect_line_line(line1, line2) ⇒ Geom::Point3d, nil

Intersection point of two infinite lines; returns nil if they are parallel and do not intersect.

Parameters:

  • line1 (Array)
  • line2 (Array)

Returns:

  • (Geom::Point3d, nil)

Examples:

line1 = [Geom::Point3d.new(20, 0, 0), Geom::Vector3d.new(0, 1, 0)]
line2 = [Geom::Point3d.new(0, 10, 0), Geom::Point3d.new(20, 10, 0)]
Geom.intersect_line_line(line1, line2).to_a  #=> [20.0, 10.0, 0.0]

Geom.intersect_line_plane(line, plane) ⇒ Geom::Point3d, nil

The intersection point of an infinite line and a plane; returns nil if they are parallel.

Parameters:

  • line (Array)
  • plane (Array)

Returns:

  • (Geom::Point3d, nil)

Examples:

line = [Geom::Point3d.new(-10, 20, 0), Geom::Vector3d.new(1, 0, 0)]
plane = [Geom::Point3d.new(10, 0, 0), Geom::Vector3d.new(1, 0, 0)]
Geom.intersect_line_plane(line, plane).to_a  #=> [10.0, 20.0, 0.0]

Geom.intersect_plane_plane(plane1, plane2) ⇒ Array(Geom::Point3d, Geom::Vector3d), nil

Intersection of two planes [point, direction]; parallel planes return nil.

Parameters:

  • plane1 (Array)
  • plane2 (Array)

Returns:

  • (Array, nil)

Examples:

plane1 = [Geom::Point3d.new(10, 0, 0), Geom::Vector3d.new(1, 0, 0)]
plane2 = [Geom::Point3d.new(0, 20, 0), Geom::Vector3d.new(0, 1, 0)]
line = Geom.intersect_plane_plane(plane1, plane2)
line[0].to_a  #=> [10.0, 20.0, 0.0]

Geom.linear_combination(weight1, point1, weight2, point2) ⇒ Geom::Point3dGeom.linear_combination(weight1, vector1, weight2, vector2) ⇒ Geom::Vector3d

Linear combination of two points or two vectors: weight1 * a weight2 * b+.

Parameters:

  • weight1 (Numeric)
  • point1 (Geom::Point3d, Geom::Vector3d)
  • weight2 (Numeric)
  • point2 (Geom::Point3d, Geom::Vector3d)

Returns:

  • (Geom::Point3d, Geom::Vector3d)

Examples:

Geom.linear_combination(0.25, Geom::Point3d.new(1, 1, 1), 0.75,
  Geom::Point3d.new(10, 10, 10)).to_a
#=> [7.75, 7.75, 7.75]

Geom.point_in_polygon_2D(point, polygon, check_border) ⇒ Boolean

Does the point lie inside the polygon. Ignore the Z coordinate of the point with respect to the polygon vertices.

Parameters:

  • point (Geom::Point3d, Array<Numeric>)
  • polygon (Array<Geom::Point3d>)
  • check_border (Boolean) Whether points on the edge are included

Returns:

  • (Boolean)

Examples:

triangle = [
  Geom::Point3d.new(0, 0, 0),
  Geom::Point3d.new(10, 0, 0),
  Geom::Point3d.new(0, 10, 0)]
Geom.point_in_polygon_2D(Geom::Point3d.new(5, 0, 10), triangle, true)

Geom.tesselate(outer, *holes) ⇒ Array<Geom::Point3d>

Triangulates a planar polygon and returns a flat list of points, three per triangle. Supply the outer loop counterclockwise and hole loops clockwise.

Parameters:

  • outer (Array<Geom::Point3d>)
  • holes (Array<Geom::Point3d>)

Returns:

  • (Array<Geom::Point3d>)

Raises:

  • [ArgumentError] A loop must have at least three points.
  • [RuntimeError] Triangulation failed

Examples:

polygon = [
  Geom::Point3d.new(0, 0, 0),
  Geom::Point3d.new(90, 0, 0),
  Geom::Point3d.new(60, 40, 0),
  Geom::Point3d.new(90, 90, 0),
  Geom::Point3d.new(30, 70, 0)]
tris = Geom.tesselate(polygon)
tris.length % 3 == 0