ModraUp Ruby API Documentation Ruby API Reference

Class: Geom::Point3d

Inherits:
Object
  • Object
show all

Overview

A point in three-dimensional space. Coordinates are stored in inches, so a bare 1 and 25.4.mm both represent one inch. As in SketchUp, Geom::Point3d#x, Geom::Point3d#y, Geom::Point3d#z, Geom::Point3d#[], and Geom::Point3d#distance return a Length.

Examples:

a = Geom::Point3d.new(0, 0, 0)
b = Geom::Point3d.new(25.4.mm, 0, 0)
b.x.is_a?(Length)  #=> true
a.distance(b) == 1.inch

Class Method Summary # collapse

Instance Method Summary # collapse

Class Method Details

Point3d.new ⇒ pointPoint3d.new(x, y, z) ⇒ pointPoint3d.new(x, y) ⇒ pointPoint3d.new([x, y, z]) ⇒ pointPoint3d.new([x, y]) ⇒ pointPoint3d.new(point) ⇒ point

Constructs a point. With no arguments, it is the origin; with two components, Z is 0. Numeric literals are in inches; also accept Length (e.g., 1.mm).

Parameters:

  • x (Numeric, Length)
  • y (Numeric, Length)
  • z (Numeric, Length)

Returns:

  • (Geom::Point3d)

Raises:

  • [ArgumentError] The number of arguments is not in the range 0..3

Examples:

Geom::Point3d.new(1, 2, 3).to_a
Geom::Point3d.new(25.4.mm, 0, 0).x == 1.inch
Geom::Point3d.new([1, 2]).z == 0

Point3d.linear_combination(weight1, point1, weight2, point2) ⇒ Geom::Point3d

Weighted sum of two points: weight1 * point1 weight2 * point2+.

Parameters:

  • weight1 (Numeric)
  • point1 (Geom::Point3d, Array<Numeric>)
  • weight2 (Numeric)
  • point2 (Geom::Point3d, Array<Numeric>)

Returns:

  • (Geom::Point3d)

Examples:

Geom::Point3d.linear_combination(0.5, [0, 0, 0], 0.5, [10, 0, 0]).to_a

Instance Method Details

point.x ⇒ Length

X coordinate, in internal inches Length. pt.x.to_mm gets the Float in millimeters; 1000.mm stored and read back is still 1000 mm.

Returns:

  • (Length)

Examples:

pt = Geom::Point3d.new(1000.mm, 0, 0)
pt.x.is_a?(Length)  #=> true
pt.x == 1000.mm
pt.x.to_mm          #=> 1000.0

point.y ⇒ Length

Y coordinate, in internal inches Length.

Returns:

  • (Length)

Examples:

Geom::Point3d.new(1, 2, 3).y == 2.inch

point.z ⇒ Length

Z coordinate, in internal inches Length.

Returns:

  • (Length)

Examples:

Geom::Point3d.new(1, 2, 3).z == 3.inch

point.x = value ⇒ value

Set the X coordinate.

Parameters:

  • value (Numeric, Length)

Returns:

  • (Numeric, Length)

Examples:

pt = Geom::Point3d.new
pt.x = 5
pt.x = 10.mm
pt.x == 10.mm

point.y = value ⇒ value

Set the Y coordinate.

Parameters:

  • value (Numeric, Length)

Returns:

  • (Numeric, Length)

Examples:

pt = Geom::Point3d.new
pt.y = 5

point.z = value ⇒ value

Set the Z coordinate.

Parameters:

  • value (Numeric, Length)

Returns:

  • (Numeric, Length)

Examples:

pt = Geom::Point3d.new
pt.z = 5

point.to_a ⇒ Array(Float, Float, Float)

Convert to [x, y, z], where x, y, and z are float values in inches, unaffected by display units and precision.

Returns:

  • (Array<Float>)

Examples:

Geom::Point3d.new(1, 2, 3).to_a == [1.0, 2.0, 3.0]

point.to_s ⇒ String

(x, y, z).

Returns:

  • (String)

Examples:

Geom::Point3d.new(1, 0, 0).to_s

point.distance(other) ⇒ Length

Returns the Euclidean distance to another point, returning Length. other can be a point or [x, y, z].

Parameters:

  • other (Geom::Point3d, Array<Numeric>)

Returns:

  • (Length)

Examples:

Geom::ORIGIN.distance(Geom::Point3d.new(3, 4, 0)) == 5.inch
Geom::ORIGIN.distance([3, 4, 0]) == 5.inch

point.offset(vector) ⇒ Geom::Point3dpoint.offset(vector, length) ⇒ Geom::Point3d

Offset the point along a vector, returning a new point. For a positive length, offset the point by that length in the direction of the vector.

Parameters:

  • vector (Geom::Vector3d, Geom::Point3d, Array<Numeric>)
  • length (Numeric, Length)

Returns:

  • (Geom::Point3d)

Examples:

Geom::ORIGIN.offset([1, 0, 0]).to_a  #=> [1.0, 0.0, 0.0]
Geom::ORIGIN.offset(Geom::Vector3d.new(0, 2, 0), 1).to_a  #=> [0.0, 1.0, 0.0]

point - point ⇒ Geom::Vector3dpoint - vector ⇒ Geom::Point3d

Subtract another point to get a vector, or subtract a vector to get a new point.

Parameters:

  • other (Geom::Point3d, Geom::Vector3d, Array<Numeric>)

Returns:

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

Examples:

(Geom::Point3d.new(1, 0, 0) - Geom::ORIGIN).to_a  #=> [1.0, 0.0, 0.0]

point == other ⇒ Boolean

Compare coordinates with another point or [x, y, z].

Parameters:

  • other (Geom::Point3d, Array<Numeric>)

Returns:

  • (Boolean)

Examples:

Geom::Point3d.new(1, 0, 0) == [1, 0, 0]

point.transform(transformation) ⇒ Geom::Point3d

Apply a transformation to a point and return the new point. Accepts values convertible to Transformation, where Vector3d is treated as a translation.

Parameters:

  • transformation (Geom::Transformation, Geom::Vector3d, Geom::Point3d, Array, Numeric)

Returns:

  • (Geom::Point3d)

Examples:

Geom::ORIGIN.transform(Geom::Transformation.translation(1, 0, 0)).to_a
#=> [1.0, 0.0, 0.0]

point.transform!(transformation) ⇒ self

Applies a transformation in place to the point. The transformation rules are the same as for #transform.

Parameters:

  • transformation (Geom::Transformation, Geom::Vector3d, Geom::Point3d, Array, Numeric)

Returns:

  • (Geom::Point3d)

Examples:

p = Geom::Point3d.new(0, 0, 0)
p.transform!(Geom::Transformation.translation(1, 0, 0))
p.to_a  #=> [1.0, 0.0, 0.0]

point + vector ⇒ Geom::Point3d

Add a vector to a Point3d, returning a new point.

Parameters:

  • vector (Geom::Vector3d, Array<Numeric>)

Returns:

  • (Geom::Point3d)

Examples:

(Geom::ORIGIN + Geom::Vector3d.new(1, 0, 0)).to_a  #=> [1.0, 0.0, 0.0]

point < other ⇒ Boolean

Compare in dictionary order by X, Y, Z.

Parameters:

  • other (Geom::Point3d, Array<Numeric>)

Returns:

  • (Boolean)

Examples:

Geom::Point3d.new(0, 0, 0) < Geom::Point3d.new(1, 0, 0)

point[index] ⇒ Length

Retrieve coordinates by index: 0 is X, 1 is Y, 2 is Z. Returns Length.

Parameters:

  • index (Integer)

Returns:

  • (Length)

Examples:

Geom::Point3d.new(1, 2, 3)[1] == 2.inch

point[index] = value ⇒ value

Set coordinates by index.

Parameters:

  • index (Integer)
  • value (Numeric, Length)

Returns:

  • (Numeric, Length)

Examples:

p = Geom::Point3d.new
p[2] = 5
p.z == 5.inch

point.clone ⇒ Geom::Point3d

Duplicates the point.

Returns:

  • (Geom::Point3d)

Examples:

a = Geom::Point3d.new(1, 2, 3)
b = a.clone
b.to_a  #=> [1.0, 2.0, 3.0]

point.inspect ⇒ String

Debug string.

Returns:

  • (String)

Examples:

Geom::ORIGIN.inspect

point.offset!(vector) ⇒ selfpoint.offset!(vector, length) ⇒ self

Translates along the vector in place.

Parameters:

  • vector (Geom::Vector3d, Array<Numeric>)
  • length (Numeric, Length)

Returns:

  • (Geom::Point3d)

Examples:

p = Geom::Point3d.new
p.offset!([0, 0, 1])
p.z == 1.inch

point.vector_to(other) ⇒ Geom::Vector3d

Returns a vector from this point to another point.

Parameters:

  • other (Geom::Point3d, Array<Numeric>)

Returns:

  • (Geom::Vector3d)

Examples:

Geom::ORIGIN.vector_to([0, 0, 2]).length == 2.inch

point.distance_to_line(line) ⇒ Float

Distance to an infinite line. The line is defined as either [point, vector] or [point, point].

Parameters:

  • line (Array)

Returns:

  • (Float)

Examples:

Geom::Point3d.new(0, 1, 0).distance_to_line([ORIGIN, Z_AXIS]) == 1.inch

point.distance_to_plane(plane) ⇒ Float

Distance to the plane. The plane is given as either [point, normal] or [A, B, C, D].

Parameters:

  • plane (Array)

Returns:

  • (Float)

Examples:

Geom::Point3d.new(0, 0, 5).distance_to_plane([ORIGIN, Z_AXIS]) == 5.inch

point.on_line?(line) ⇒ Boolean

Does the point lie on the infinite line (within a length tolerance).

Parameters:

  • line (Array)

Returns:

  • (Boolean)

Examples:

Geom::Point3d.new(0, 0, 3).on_line?([ORIGIN, Z_AXIS])

point.on_plane?(plane) ⇒ Boolean

Does the point lie on the plane (within a length tolerance).

Parameters:

  • plane (Array)

Returns:

  • (Boolean)

Examples:

Geom::ORIGIN.on_plane?([0, 0, 1, 0])

point.project_to_line(line) ⇒ Geom::Point3d

Projects to the nearest point on an infinite line.

Parameters:

  • line (Array)

Returns:

  • (Geom::Point3d)

Examples:

Geom::Point3d.new(1, 1, 0).project_to_line([ORIGIN, X_AXIS]).to_a
#=> [1.0, 0.0, 0.0]

point.project_to_plane(plane) ⇒ Geom::Point3d

Projects to the nearest point on the plane.

Parameters:

  • plane (Array)

Returns:

  • (Geom::Point3d)

Examples:

Geom::Point3d.new(0, 0, 4).project_to_plane([ORIGIN, Z_AXIS]).to_a
#=> [0.0, 0.0, 0.0]

point.set!(x, y, z) ⇒ selfpoint.set!(point) ⇒ selfpoint.set!(array) ⇒ self

Sets the coordinates of the point.

Returns:

  • (Geom::Point3d)

Examples:

p = Geom::Point3d.new
p.set!(1, 2, 3)
p.to_a  #=> [1.0, 2.0, 3.0]