Class: Array

Inherits:
Object show all
Defined in:
lib/array.rb

Overview

Note:

In SketchUp, Arrays may be used in place of either Geom::Point3d and Geom::Vector3d objects depending on how they are used.

The SketchUp Array class adds additional methods to the standard Ruby Array class. Specifically, it contains methods allowing an array to behave just as a Geom::Vector3d or Geom::Point3d object (which can be thought of as arrays of 3 coordinate values). Therefore, you can use the Array class in place of a Geom::Point3d or Geom::Vector3d as a way to pass coordinate values.

In addition to the built-in Ruby Array methods, the following methods have been added by SketchUp.

Examples:

# An array of 3 values can represent a 1" long vector pointing straight
# up in the z-direction.
array = [0, 0, 1]

# An array of 3 values can also represent a point 1" above the origin in
# the z direction. (Note that this is the exact same array.)
array = [0, 0, 1]

# How it is interpreted is based on context. For example, this code will
# create a construction point at position 0, 0, 1, since in this context
# a Point3d is expected.
entities = Sketchup.active_model.entities
construction_point = entities.add_cpoint(array)

# Whereas this will move our construction point 1" upward, since in this
# context a Vector3d is expected.
transformation = Geom::Transformation.new(array)
entities.transform_entities(transformation, construction_point)

See Also:

Since:

  • SketchUp 6.0

Instance Method Summary collapse

Instance Method Details

#cross(vector) ⇒ Vector3d

Compute the cross product between two vectors, particularly this vector and the given vector.

Examples:

vector1 = Geom::Vector3d.new(0, 1, 0)
array = [1, 0, 0]
This will return a new Vector3d
vector2 = array.cross(vector1)

Parameters:

Returns:

  • (Vector3d)

    Computed cross product.

Since:

  • SketchUp 6.0



50
51
# File 'lib/array.rb', line 50

def cross(vector)
end

#distance(point) ⇒ Length

Compute the distance between this point and the given point.

Examples:

[0,0].distance([1,1]) # ==> 1.414
ORIGIN.distance([1,1,1]) # ==> 1.732
point = Geom::Point3d.new(10, 10, 10)
array = [1, 1, 1]
# This will return a Length
distance = array.distance(point)

Parameters:

Returns:

  • (Length)

    Computed distance.

Since:

  • SketchUp 6.0



68
69
# File 'lib/array.rb', line 68

def distance(point)
end

#distance_to_line(line) ⇒ Length

Compute the distance from the current point to a line. Lines are defined by an array of a point and a vector or an array of two points. See the Geom module for instructions on how to create a line.

Examples:

line = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a Length
distance = array.distance_to_line(line)

Parameters:

Returns:

  • (Length)

    Computed distance.

Since:

  • SketchUp 6.0



86
87
# File 'lib/array.rb', line 86

def distance_to_line(line)
end

#distance_to_plane(plane) ⇒ Length

Compute the distance from the current point to a plane. See the Geom module for instructions on how to create a plane.

Examples:

plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a Length
distance = array.distance_to_plane(plane)

Parameters:

Returns:

  • (Length)

    Computed distance.

Since:

  • SketchUp 6.0



103
104
# File 'lib/array.rb', line 103

def distance_to_plane(plane)
end

#dot(vector) ⇒ Float

Compute the dot product between the current and the specified vector.

Examples:

[0, 0, 1].dot([0, 1, 0]) # ==> 0.0
vector = Geom::Vector3d.new(0, 1, 0)
array = [1, 0, 0]
# This will return a Float, in this case 22.0
dot_product = array.dot(vector)

Parameters:

  • vector (Vector3d)

Returns:

  • (Float)

    Computed dot product.

Since:

  • SketchUp 6.0



120
121
# File 'lib/array.rb', line 120

def dot(vector)
end

#normalizeArray

Normalize the current vector (setting its length to one). It returns a new array rather than changing the original in place.

Examples:

array = [1, 2, 3]
# This will return a new Array
normal_vector = array.normalize

Returns:

  • (Array)

    A new array representing the normalized vector.

Since:

  • SketchUp 6.0



132
133
# File 'lib/array.rb', line 132

def normalize
end

#normalize!Array

Normalize the current vector in place (settings its length to one).

Examples:

array = [1, 2, 3]
# This will modify the 'array' in place.
normal_vector = array.normalize!

Returns:

  • (Array)

    The current array with the normalized vector.

Since:

  • SketchUp 6.0



143
144
# File 'lib/array.rb', line 143

def normalize!
end

#offset(vector) ⇒ Array

Offset current point by a vector. This returns a new array rather than modifying the original in place.

Examples:

array = [10, 10, 10]
vector = Geom::Vector3d.new(0, 0, 1)
# This will return a new Array
point = array.offset(vector)

Parameters:

Returns:

  • (Array)

    The newly offset array.

Since:

  • SketchUp 6.0



158
159
# File 'lib/array.rb', line 158

def offset(vector)
end

#offset!(vector) ⇒ Array

Offset current point by a vector in place. This modifies the current array.

Examples:

array = [10, 10, 10]
vector = Geom::Vector3d.new(0, 0, 1)
# This will modify 'array' in place.
point = array.offset!(vector)

Parameters:

Returns:

  • (Array)

    The current offset array.

Since:

  • SketchUp 6.0



172
173
# File 'lib/array.rb', line 172

def offset!(vector)
end

#on_line?(line) ⇒ Boolean

Determine if the current point is on the given line. See the Geom module for instructions on how to create a line.

Examples:

line = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a true or false value
on_plane = array.on_line?(line)

Parameters:

Returns:

  • (Boolean)

    +true+ if the point is on the line or +false+ if the point is not on the line.

Since:

  • SketchUp 6.0



190
191
# File 'lib/array.rb', line 190

def on_line?(line)
end

#on_plane?(plane) ⇒ Boolean

Determine if the current point is on the given plane. See the Geom module for instructions on how to create a plane.

Examples:

plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return false because the current point is not on the plane.
on_plane = array.on_plane?(plane)

Parameters:

Returns:

  • (Boolean)

    +true+ if the point is on the plane or +false+ if the point is not on the plane.

Since:

  • SketchUp 6.0



208
209
# File 'lib/array.rb', line 208

def on_plane?(plane)
end

#project_to_line(line) ⇒ Array

Project point onto a line. See the Geom module for instructions on how to create a line.

Examples:

line = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a new Array
point_on_line = array.project_to_line(line)

Parameters:

Returns:

  • (Array)

    A new point on the line that is closest to this point if successful.

Since:

  • SketchUp 6.0



226
227
# File 'lib/array.rb', line 226

def project_to_line(line)
end

#project_to_plane(plane) ⇒ Array

Project point onto a plane. See the Geom module for instructions on how to create a plane.

Examples:

plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a new Array
point_on_line = array.project_to_plane(plane)

Parameters:

Returns:

  • (Array)

    A new point on the plane that is closest to this point if successful.

Since:

  • SketchUp 6.0



244
245
# File 'lib/array.rb', line 244

def project_to_plane(plane)
end

#transform(transformation) ⇒ Array

Apply Geom::Transformation object to the current point defined by an Array object. This method returns a new transformed point rather than modifying the current point.

Examples:

point = Geom::Point3d.new(10, 20, 30)
transform = Geom::Transformation.new(point)
array = [1, 2, 3]
# This will return a new Array
array.transform(transform)

Parameters:

Returns:

  • (Array)

    The newly transformed point.

Since:

  • SketchUp 6.0



261
262
# File 'lib/array.rb', line 261

def transform(transformation)
end

#transform!(transformation) ⇒ Array

Apply Geom::Transformation object to the current point defined by an Array object. This method modifies the current point.

Examples:

point = Geom::Point3d.new(10, 20, 30)
transform = Geom::Transformation.new(point)
array = [1, 2, 3]
# This will modify 'array' in place
array.transform!(transform)

Parameters:

Returns:

  • (Array)

    The current transformed point.

Since:

  • SketchUp 6.0



277
278
# File 'lib/array.rb', line 277

def transform!(transformation)
end

#vector_to(point) ⇒ Geom::Vector3d

Compute vector from the current point to the given point.

Examples:

point = Geom::Point3d.new(10, 20, 30)
array = [1, 2, 3]
# This will return a new Vector3d
vector = array.vector_to(point)

Parameters:

Returns:

Since:

  • SketchUp 6.0



291
292
# File 'lib/array.rb', line 291

def vector_to(point)
end

#xNumeric

Get the X coordinate or the first element of the array.

Examples:

[1, 2, 3].x # ==> 1
array = [1, 2, 3]
# This will return a Fixnum, in this case 1
x = array.x

array = [1.0, 2.0, 3.0]
# This will return a Float, in this case 1.0
x = array.x

Returns:

  • (Numeric)

    The X coordinate or the first element.

Since:

  • SketchUp 6.0



309
310
# File 'lib/array.rb', line 309

def x
end

#x=Object

Set the X coordinate or the first element of the array.

Examples:

array = [1, 2, 3]
# This will initialize the x value as a Float
array.x = 2.5
# This will initialize the x value as a Fixnum
array.x = 5

Returns:

  • (Object)

    The newly assigned value.

Since:

  • SketchUp 6.0



322
323
# File 'lib/array.rb', line 322

def x=
end

#yNumeric

Get the Y coordinate or the second element of the array.

Examples:

[1, 2, 3].y # ==> 2
array = [1, 2, 3]
# This will return a Fixnum, in this case 2
y = array.y

array = [1.0, 2.0, 3.0]
# This will return a Float, in this case 2.0
y = array.y

Returns:

  • (Numeric)

    The Y coordinate or the second element.

Since:

  • SketchUp 6.0



340
341
# File 'lib/array.rb', line 340

def y
end

#y=Object

Set the Y coordinate or the second element of the array.

Examples:

array = [1, 2, 3]
# This will initialize the y value as a Float
array.y = 2.5
# This will initialize the y value as a Fixnum
array.y = 5

Returns:

  • (Object)

    The newly assigned value.

Since:

  • SketchUp 6.0



353
354
# File 'lib/array.rb', line 353

def y=
end

#zNumeric

Get the Z coordinate or the third element of the array.

Examples:

[1, 2, 3].z # ==> 2
array = [1, 2, 3]
# This will return a Fixnum, in this case 3
z = array.z

array = [1.0, 2.0, 3.0]
# This will return a Float, in this case 3.0
z = array.z

Returns:

  • (Numeric)

    The Z coordinate or the third element.

Since:

  • SketchUp 6.0



371
372
# File 'lib/array.rb', line 371

def z
end

#z=Object

Set the Z coordinate or the third element of the array.

Examples:

array = [1, 2, 3]
# This will initialize the z value as a Float
array.z = 2.5
# This will initialize the z value as a Fixnum
array.z = 5

Returns:

  • (Object)

    The newly assigned value.

Since:

  • SketchUp 6.0



384
385
# File 'lib/array.rb', line 384

def z=
end