Class: Geom::Point3d

Inherits:
Object
  • Object
show all
Defined in:
lib/sketchup-api-stubs/stubs/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(array3d) ⇒ Geom::Point3d #initialize(array2d) ⇒ Geom::Point3d #initialize(input_point) ⇒ Geom::Point3d #initialize(vertex) ⇒ 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



327
328
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 327

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)

# Get the point that is half the way from point1 to point2.
points = Geom::Point3d.linear_combination(0.5, point1, 0.5, point2)

# Get the point that is 3/4 the way from point1 to point2.
point = Geom::Point3d.linear_combination(0.25, point1, 0.75, point2)

# Get the point that is 70% the way from point1 to point2.
percentage = 0.7
point = Geom::Point3d.linear_combination(1.0 - percentage, point1, percentage, point2)

Parameters:

Returns:

Version:

  • SketchUp 6.0



68
69
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 68

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

Instance Method Details

#+(vector) ⇒ Geom::Point3d

The #+ operator is a fast way to add to the current x, y and z values of a vector.

Examples:

Using vector

point1 = Geom::Point3d.new(1, 2, 3)
vector = Geom::Vector3d.new(4, 5, 6)
point2 = point1 + vector

Using array

point1 = Geom::Point3d.new(1, 2, 3)
point2 = point1 + [10,10,10]

Using point

point1 = Geom::Point3d.new(1, 2, 3)
point2 = Geom::Point3d.new(4, 5, 6)
# This works because SketchUp treats the array of triple numerics as
# a vector in this case.
point3 = point1 + point2.to_a

Parameters:

Returns:

Version:

  • SketchUp 6.0



97
98
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 97

def +(vector)
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



113
114
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 113

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



130
131
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 130

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



163
164
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 163

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



182
183
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 182

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



202
203
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 202

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



215
216
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 215

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:

Version:

  • SketchUp 6.0



232
233
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 232

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



254
255
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 254

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



274
275
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 274

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



343
344
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 343

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



364
365
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 364

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



387
388
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 387

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)

Version:

  • SketchUp 6.0



405
406
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 405

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)

Version:

  • SketchUp 6.0



422
423
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 422

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



442
443
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 442

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



464
465
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 464

def project_to_plane(plane)
end

#set!(x, y, z) ⇒ Geom::Point3d #set!(array3d) ⇒ Geom::Point3d #set!(point3d) ⇒ 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



491
492
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 491

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



508
509
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 508

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



520
521
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 520

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



538
539
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 538

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



555
556
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 555

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



577
578
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 577

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



589
590
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 589

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



604
605
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 604

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



616
617
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 616

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



631
632
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 631

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



643
644
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 643

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



658
659
# File 'lib/sketchup-api-stubs/stubs/Geom/Point3d.rb', line 658

def z=(value)
end