Class: Geom::Point3d

Inherits:
Object
  • Object
show all
Defined in:
SketchUp/Geom/Point3d.rb

Overview

The Point3d class allows you to work with a point in 3D space. The point is basically just a series of values representing x, y and z coordinates.

The values are specified as [x,y,z]. For example [100,200,300]. To create a point call Geom::Point3d.new, where the creation method can take a variety of arguments:

In addition to the methods below, there are a series of geometry related methods that are on the Array class, since Point3d objects can also be represented as a 3-element Array. These Array-level methods are for operations such as determining if a point is on a line, on a plane, etc. See the Array class for details.

Examples:

# No arguments, creates a point at the origin [0,0,0]
pt1 = Geom::Point3d.new

# Creates a point at x of 100, y of 200, z of 300.
pt2 = Geom::Point3d.new(100,200,300)

# You can also create a point directly by simply assigning the x, y and z
# values to a variable as an array:
pt3 = [100,200,300]

Version:

  • SketchUp 6.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeom::Point3d #initialize(x, y, z = 0.0) ⇒ Geom::Point3d #initialize(point3d) ⇒ Geom::Point3d #initialize(vertex) ⇒ Geom::Point3d #initialize(array2d) ⇒ Geom::Point3d #initialize(input_point) ⇒ Geom::Point3d #initialize(array3d) ⇒ Geom::Point3d

The new method is used to create a new 3D point.

Examples:

# No arguments, creates a point at the origin [0,0,0]
pt1 = Geom::Point3d.new

# Creates a point at x of 100, y of 200, z of 300.
pt2 = Geom::Point3d.new(100,200,300)

# You can also create a point directly by simply assigning the x, y and z
# values to a variable as an array:
pt3 = [100,200,300]

Overloads:

Version:

  • SketchUp 6.0



316
317
# File 'SketchUp/Geom/Point3d.rb', line 316

def initialize(*args)
end

Class Method Details

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

The linear_combination method is used to create a new point as a linear combination of two points. This method is generally used to get a point at some percentage along a line connecting the two points.

A linear combination is a standard term for vector math. It is defined as point = weight1 * point1 + weight2 * point2.

Examples:

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::Point3d.linear_combination(0.25, point1, 0.75, point2)
if (point)
  UI.messagebox(point)
else
  UI.messagebox("Failure")
end

Parameters:

  • weight1 (Float)

    A weight or percentage.

  • point2 (Float)

    The end point of the line.

  • weight2 (Float)

    A weight or percentage.

  • point1 (Float)

    The start point on the line.

Returns:

Version:

  • SketchUp 6.0



68
69
# File 'SketchUp/Geom/Point3d.rb', line 68

def self.linear_combination(weight1, point1, weight2, point2)
end

Instance Method Details

#+(point2) ⇒ Geom::Point3d

The ‘+’ operator is a fast way to add to the current x, y and z values of a point, or to set the values of a point by adding to other points together.

Examples:

pt2 = pt + vec
pt = pt + [10,10,10]

Parameters:

Returns:

Version:

  • SketchUp 6.0



86
87
# File 'SketchUp/Geom/Point3d.rb', line 86

def +(point2)
end

#-(point2) ⇒ Geom::Vector3d

The ‘-’ operator is a fast way to subtract from the current x, y and z values of a point.

Examples:

pt2 = pt - vec
pt = pt - [10,10,10]

Parameters:

Returns:

Version:

  • SketchUp 6.0



102
103
# File 'SketchUp/Geom/Point3d.rb', line 102

def -(point2)
end

#<(point2) ⇒ Boolean

The ‘<’ operator is a fast way to determine if another point is closer to the origin.

Examples:

pt1 = Geom::Point3d.new(10,10,10)
pt2 = Geom::Point3d.new(20,20,20)
result = pt1 < pt2

Parameters:

Returns:

  • (Boolean)

    true if the point2 is closer to the origin.

Version:

  • SketchUp 6.0



119
120
# File 'SketchUp/Geom/Point3d.rb', line 119

def <(point2)
end

#==(point2) ⇒ Boolean

The == method is used to compare two points for equality.

This uses the standard SketchUp tolerance to determine if two points are the same.

Points can be compared to one another or to an array representing x, y and z coordinates, as in the following examples:

Examples:

if( pt1 == pt2 )
  UI.messagebox('equal')
end

# ... or ...
if( pt1 == [100,200,300] ) ...
  UI.messagebox('equal')
end
point1 = Geom::Point3d.new(1,1,1)
point2 = Geom::Point3d.new(10,10,10)
status = point1 == point2

Parameters:

Returns:

  • (Boolean)

    true if both points are equal; false if points are not equal

Version:

  • SketchUp 6.0



152
153
# File 'SketchUp/Geom/Point3d.rb', line 152

def ==(point2)
end

#[](index) ⇒ Length

The [] method is used to retrieve the value of the point at the specified index.

Examples:

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

# retrieves the y value of 2
yvalue = point[1]

Parameters:

  • index (Integer)

    The index for a specific x, y, or z value within the Point3d.

Returns:

  • (Length)

    an x, y, or z value if successful

Version:

  • SketchUp 6.0



171
172
# File 'SketchUp/Geom/Point3d.rb', line 171

def [](index)
end

#[]=(index, new_value) ⇒ Numeric

The []= method is used to set the x, y, or z value of the point based on the specific index of the value.

Examples:

point = Geom::Point3d.new(1,2,3)
yvalue = point[1] = 4

Parameters:

  • index (Integer)

    The index for a specific x, y, or z value within the Point3d.

  • new_value (Numeric)

    New x, y, or z value.

Returns:

  • (Numeric)

    the newly set x, y, or z value if successful

Version:

  • SketchUp 6.0



191
192
# File 'SketchUp/Geom/Point3d.rb', line 191

def []=(index, new_value)
end

#cloneGeom::Point3d

The clone method is used to create another point identical to the point being cloned.

Examples:

point = Geom::Point3d.new(1,2,3)
newpoint = point.clone

Returns:

Version:

  • SketchUp 6.0



204
205
# File 'SketchUp/Geom/Point3d.rb', line 204

def clone
end

#distance(point2) ⇒ Length

The distance method is used to compute the distance from a point to another point.

Examples:

point1 = Geom::Point3d.new(1,1,1)
point2 = Geom::Point3d.new(10,10,10)
distance = point1.distance(point2)

Parameters:

  • point2 (Geom::Point3d)

    The Point3d object to compute the distance to.

Returns:

  • (Length)

    the distance in current units

Version:

  • SketchUp 6.0



221
222
# File 'SketchUp/Geom/Point3d.rb', line 221

def distance(point2)
end

#distance_to_line(line) ⇒ Float

Note:

This function returns a ‘Float` value, not a `Length`.

The distance_to_line method is used to compute the distance from a point to a line.

See Geom module for how to specify a line.

Examples:

point1 = Geom::Point3d.new(1,1,1)
line = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
distance = point1.distance_to_line(line)

Parameters:

  • line

    A line (see Geom for information on creating lines).

Returns:

  • (Float)

    the distance between a point and line in internal units if successful

Version:

  • SketchUp 6.0



243
244
# File 'SketchUp/Geom/Point3d.rb', line 243

def distance_to_line(line)
end

#distance_to_plane(plane) ⇒ Float

Note:

This function returns a ‘Float` value, not a `Length`.

The distance_to_plane method is used to compute the distance from the point to a plane.

See module Geom for how to specify a plane.

Examples:

distance = point.distance_to_plane(plane)

Parameters:

  • plane

    A plane (see Geom for how to create a plane).

Returns:

  • (Float)

    a distance between a point and a plane in internal units if successful

Version:

  • SketchUp 6.0



263
264
# File 'SketchUp/Geom/Point3d.rb', line 263

def distance_to_plane(plane)
end

#inspectString

The inspect method is used to format a 3D point as a string.

You will not often use these function directly. Instead, they are called automatically when an object is output using a print command like ‘puts’, which writes to the Ruby console.

Examples:

point = Geom::Point3d.new(10,10,10)
string = point.inspect

Returns:

  • (String)

    a string point representation

Version:

  • SketchUp 6.0



332
333
# File 'SketchUp/Geom/Point3d.rb', line 332

def inspect
end

#offset(vector, length = vector.length) ⇒ Geom::Point3d

The offset method is used to offset a point by a vector and return a new point. The length of the vector must not be zero.

Examples:

point1 = Geom::Point3d.new(10,10,10)
vector = Geom::Vector3d.new(0, 0, 1)
point2 = point1.offset(vector)

Parameters:

  • vector (Geom::Vector3d)

    A Vector3d object to offset the point by.

  • length (Numeric) (defaults to: vector.length)

    the distance to offset. If not provided, the offset is my a distance equal to the vector length.

Returns:

Version:

  • SketchUp 6.0



353
354
# File 'SketchUp/Geom/Point3d.rb', line 353

def offset(vector, length = vector.length)
end

#offset!(vector, length = vector.length) ⇒ Geom::Point3d

The offset! method is used to offset a point by a vector. The point itself is modified.

Unlike offset, the point itself is modified.

Examples:

point1 = Geom::Point3d.new(10,10,10)
vector = Geom::Vector3d.new(0,0,1)
point2 = point1.offset!(vector)

Parameters:

  • vector (Geom::Vector3d)

    A Vector3d object to offset the point by.

  • length (Numeric) (defaults to: vector.length)

    the distance to offset. If not provided, the offset is my a distance equal to the vector length.

Returns:

Version:

  • SketchUp 6.0



376
377
# File 'SketchUp/Geom/Point3d.rb', line 376

def offset!(vector, length = vector.length)
end

#on_line?(line) ⇒ Boolean

The on_line? method is used to determine if the point is on a line.

See module Geom for the various ways to specify a line.

Examples:

line = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
point = Geom::Point3d.new(10,10,10)
status = point.on_line?(line)

Parameters:

  • line

    A line (see Geom for how to create a line).

Returns:

  • (Boolean)
  • (Boolean)

Version:

  • SketchUp 6.0



396
397
# File 'SketchUp/Geom/Point3d.rb', line 396

def on_line?(line)
end

#on_plane?(plane) ⇒ Boolean

The on_plane? method is used to determine if the point is on a plane.

See module Geom for the various ways to specify a plane.

Examples:

plane = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
point = Geom::Point3d.new(10,10,10)
status = point.on_plane?(plane)

Parameters:

  • plane

Returns:

  • (Boolean)
  • (Boolean)

Version:

  • SketchUp 6.0



415
416
# File 'SketchUp/Geom/Point3d.rb', line 415

def on_plane?(plane)
end

#project_to_line(line) ⇒ Geom::Point3d

The project_to_line method is used to retrieve the point on a line that is closest to this point.

The line may be defined by either a point and a vector or by two points.

Examples:

line = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
point = Geom::Point3d.new(10,10,10)
projected_point = point.project_to_line(line)

Parameters:

  • line

    see Geom for how to specify a line

Returns:

  • (Geom::Point3d)

    the Point3d that is on a line closest to the point

Version:

  • SketchUp 6.0



435
436
# File 'SketchUp/Geom/Point3d.rb', line 435

def project_to_line(line)
end

#project_to_plane(plane) ⇒ Geom::Point3d

The project_to_plane method is used to retrieve the point on a plane that is closest to the point.

The plane may be defined by either a point on the plane and a vector perpendicular to the plane or by the coeficients to the plane equation AX + BY + CZ + D = 0. See Geom for details.

Examples:

plane = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
point = Geom::Point3d.new(10,10,10)
projected_point = point.project_to_plane(plane)

Parameters:

  • plane

    A plane (see Geom for how to create a plane).

Returns:

  • (Geom::Point3d)

    the Point3d that is on a plane closest to the point

Version:

  • SketchUp 6.0



457
458
# File 'SketchUp/Geom/Point3d.rb', line 457

def project_to_plane(plane)
end

#set!(x, y, z) ⇒ Geom::Point3d #set!(point3d) ⇒ Geom::Point3d #set!(array3d) ⇒ Geom::Point3d

The #set! method is used to set the values of the Point3d.

Examples:

point = Geom::Point3d.new(10,10,10)
point = point.set!(100,200,300)

Overloads:

Version:

  • SketchUp 6.0



484
485
# File 'SketchUp/Geom/Point3d.rb', line 484

def set!(*args)
end

#to_aArray(Length, Length, Length)

The to_a method is used to convert the point to an array of 3 numbers

Examples:

point = Geom::Point3d.new(10,20,30)
array = point.to_a

pt = [100,200,300]
# outputs [100.0,200.0,300.0]
UI.messagebox(pt.to_a)

Returns:

Version:

  • SketchUp 6.0



501
502
# File 'SketchUp/Geom/Point3d.rb', line 501

def to_a
end

#to_sString

The to_s method is used to retrieve a string representation of a point.

Examples:

point = Geom::Point3d.new(10,10,10)
str = point.to_s

Returns:

  • (String)

    the string representation of the Point3d

Version:

  • SketchUp 6.0



513
514
# File 'SketchUp/Geom/Point3d.rb', line 513

def to_s
end

#transform(transform) ⇒ Geom::Point3d

Apply a Transformation to a point, returning a new point. The original vector is unchanged by this method.

Examples:

transform = Geom::Transformation.new(point2)
point2 = Geom::Point3d.new(100,200,300)
point1 = Geom::Point3d.new(10,10,10)
point3 = point1.transform(transform)

Parameters:

Returns:

Version:

  • SketchUp 6.0



531
532
# File 'SketchUp/Geom/Point3d.rb', line 531

def transform(transform)
end

#transform!(transform) ⇒ Geom::Point3d

Apply a Transformation to a point. The point itself is modified.

Examples:

transform = Geom::Transformation.new(point2)
point2 = Geom::Point3d.new(100,200,300)
point1 = Geom::Point3d.new(10,10,10)
point1.transform!(transform)

Parameters:

Returns:

Version:

  • SketchUp 6.0



548
549
# File 'SketchUp/Geom/Point3d.rb', line 548

def transform!(transform)
end

#vector_to(point2) ⇒ Geom::Vector3d

The vector_to team method retrieves the vector between points.

Examples:

point2 = Geom::Point3d.new(100,200,300)
point1 = Geom::Point3d.new(10,10,10)
vector = point1.vector_to(point2)

# Another example...
pt1 = [1,1,0]
pt2 = [3,1,0]
pt1.vector_to(pt2) # returns the vector (2,0,0)
pt1.vector_to(pt2) # is equivalent to (pt2 - pt1)

Parameters:

Returns:

Version:

  • SketchUp 6.0



570
571
# File 'SketchUp/Geom/Point3d.rb', line 570

def vector_to(point2)
end

#xLength

The x method retrieves the x value of the 3D point.

Examples:

point = Geom::Point3d.new(1,2,3)
x = point.x

Returns:

Version:

  • SketchUp 6.0



582
583
# File 'SketchUp/Geom/Point3d.rb', line 582

def x
end

#x=(value) ⇒ Numeric

The x= method is used to set the x value of a 3D point.

Examples:

point = Geom::Point3d.new(1,2,3)
x = point.x = 2

Parameters:

  • value (Numeric)

    The new x value.

Returns:

  • (Numeric)

    the newly set x value

Version:

  • SketchUp 6.0



597
598
# File 'SketchUp/Geom/Point3d.rb', line 597

def x=(value)
end

#yLength

The y method retrieves the y value of the 3D point.

Examples:

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

Returns:

Version:

  • SketchUp 6.0



609
610
# File 'SketchUp/Geom/Point3d.rb', line 609

def y
end

#y=(value) ⇒ Numeric

The y= method is used to set the y value of a 3D point.

Examples:

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

Parameters:

  • value (Numeric)

    The new y value.

Returns:

  • (Numeric)

    the newly set y value

Version:

  • SketchUp 6.0



624
625
# File 'SketchUp/Geom/Point3d.rb', line 624

def y=(value)
end

#zLength

The z method retrieves the z value of the 3D point.

Examples:

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

Returns:

Version:

  • SketchUp 6.0



636
637
# File 'SketchUp/Geom/Point3d.rb', line 636

def z
end

#z=(value) ⇒ Numeric

The z= method is used to set the z value of a 3D point.

Examples:

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

Parameters:

  • value (Numeric)

    The new z value.

Returns:

  • (Numeric)

    the newly set z value

Version:

  • SketchUp 6.0



651
652
# File 'SketchUp/Geom/Point3d.rb', line 651

def z=(value)
end