class Geom::Vector3d

The Vector3d class is used to represent vectors in a 3 dimensional space. Vectors in SketchUp have a direction and a length, but not a starting point.

There are numerous tutorials on 3D vectors available on the internet.

@version SketchUp 6.0

Public Class Methods

linear_combination(*args) click to toggle source

The {.linear_combination} method is used to create a new vector as a linear combination of other vectors. This method is generally used to get a vector at some percentage between two vectors.

A linear combination is a standard term for vector math. It is defined as vector = weight1 * vector1 + weight2 * vector2.

@example

# Create a vector that is a 50%/50% linear combination of two others.
vec1 = Geom::Vector3d.new 3,0,0
vec2 = Geom::Vector3d.new 0,3,0
new_vector = Geom::Vector3d.linear_combination(0.5, vec1, 0.5, vec2)
# new_vector will now contain a Vector3d(1.5, 1.5, 0)

@overload linear_combination(weight1, vector1, weight2, vector2)

@param [Numeric] weight1  A weight or percentage.
@param [Geom::Vector3d] vector1  The first vector.
@param [Numeric] weight2  A weight or percentage.
@param [Geom::Vector3d] vector2  The second vector.
@return [Geom::Vector3d]

@overload linear_combination(x, xaxis, y, yaxis, z, zaxis)

@param [Numeric] x  A weight or percentage for the x axis.
@param [Geom::Vector3d] xaxis  The x axis vector.
@param [Numeric] y  A weight or percentage for the y axis.
@param [Geom::Vector3d] yaxis  The y axis vector.
@param [Numeric] z  A weight or percentage for the z axis.
@param [Geom::Vector3d] zaxis  The z axis vector.
@return [Geom::Vector3d]

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 47
def self.linear_combination(*args)
end
new(*args) click to toggle source

The new method is used to create a new vector.

@example

# A vector that runs up the Z axis.
vector = Geom::Vector3d.new(0,0,1)
if (vector)
  UI.messagebox vector
else
  UI.messagebox "Failure"
end

@overload initialize

@return [Geom::Vector3d]

@overload initialize(x, y, z)

@param [Numeric] x
@param [Numeric] y
@param [Numeric] z
@return [Geom::Vector3d]

@overload initialize(array3d)

@param [Array(Numeric, Numeric, Numeric)] array3d
@return [Geom::Vector3d]

@overload initialize(array2d)

@param [Array(Numeric, Numeric)] array2d
@return [Geom::Vector3d]

@overload initialize(vector)

@param [Geom::Vector3d] vector A Vector3d object.
@return [Geom::Vector3d]

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 340
def initialize(*args)
end

Public Instance Methods

%(vector) click to toggle source

The {#%} method is used to compute the dot product between two vectors.

This is an alias of the {#dot} method.

@example

vector1 = Geom::Vector3d.new(0, 0, 1)
vector2 = Geom::Vector3d.new(0, 1, 0)
dot = vector1 % vector2

@param [Geom::Vector] vector

@return [Float]

@see dot

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 68
def %(vector)
end
*(vector) click to toggle source

The {#cross} method is used to compute the cross product between two vectors.

The cross product, also called the vector product, is an operation on two vectors. The cross product of two vectors produces a third vector which is perpendicular to the plane in which the first two lie.

@example

vector1 = Geom::Vector3d.new(1,0,0)
vector2 = Geom::Vector3d.new(0,1,0)
vector3 = vector1 * vector2

@example

vector = Geom::Vector3d.new(1,0,0)
vector2 = Geom::Vector3d.new(0,1,0)
vector3 = vector.cross(vector2)

@param [Geom::Vector3d] vector

A Vector3d object.

@return [Geom::Vector3d] the cross of vector1 and vector2

@see *

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 95
def *(vector)
end
+(vector2) click to toggle source

The - method is used to add a vector to this one.

@example

vector = Geom::Vector3d.new(0,0,2)
vector2 = Geom::Vector3d.new(0,1,0)
new_vector = vector + vector2

@param vector2

A Vector3d object.

@return [Geom::Vector3d] the new vector.

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 111
def +(vector2)
end
-(vector2) click to toggle source

The - method is used to subtract a vector from this one.

@example

vector = Geom::Vector3d.new(0,0,2)
vector2 = Geom::Vector3d.new(0,1,0)
new_vector = vector - vector2

@param vector2

A Vector3d object.

@return [Geom::Vector3d] the new vector.

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 127
def -(vector2)
end
<(vector2) click to toggle source

The < method is used to determine if a vector's x, y or z value is less than another vector's x, y or z value.

@example

vector = Geom::Vector3d.new(0,0,2)
vector2 = Geom::Vector3d.new(0,1,0)
lt = vector < vector2

@param vector2

A Vector3d object.

@return [Boolean] true if the vector's x, y or z component is less

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 144
def <(vector2)
end
==(vector2) click to toggle source

The == method is used to determine if two vectors are equal to within tolerance.

@example

vector = Geom::Vector3d.new(1,0,0)
vector2 = Geom::Vector3d.new(0,1,0)
status = vector == vector2
# Returns false
UI.messagebox status

@param vector2

A Vector3d object.

@return [Boolean]

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 163
def ==(vector2)
end
[](i) click to toggle source

The [] method is used to access the coordinates of a vector as if it was an Array. The index must be 0, 1 or 2.

The following are equivalent:

@example

x = vector.x
x = vector[0]

@example

vector = Geom::Vector3d.new(1,0,0)
value = vector[0]
if (value)
  UI.messagebox value
else
  UI.messagebox "Failure"
end

@param [Integer] i

An index into an array of three coordinates.

@return [Length] the value for the x, y, or z coordinate.

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 190
def [](i)
end
[]=(index, value) click to toggle source

The []= method is used to set the coordinates of a vector as if it was an Array. The value of i must be 0, 1 or 2.

@example

vector[i] = coordinate

@param [Integer] index

The index for the x, y, or z coordinate.

@param [Numeric] value

The value for the x, y, or z coordinate.

@return [Numeric] the newly set coordinate value

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 208
def []=(index, value)
end
angle_between(vector2) click to toggle source

The angle_between method is used to compute the angle (in radians) between this vector and another vector.

@example

vector1 = Geom::Vector3d.new(1,0,0)
vector2 = Geom::Vector3d.new(0,1,0)
angle = vector1.angle_between vector2

@param [Geom::Vector3d] vector2

A Vector3d object.

@return [Float] an angle (in radians)

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 225
def angle_between(vector2)
end
axes() click to toggle source

The axes method is used to compute an arbitrary set of axes with the given vector as the z-axis direction.

Returns an Array of three vectors [xaxis, yaxis, zaxis]

@example

vector = Geom::Vector3d.new(1,0,0)
a = vector.axes

@return [Array(Geom::Vector3d, Geom::Vector3d, Geom::Vector3d)] an Array object containing three Vector3d objects

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 240
def axes
end
clone() click to toggle source

The clone method is used to make a copy of a vector.

This method is equivalent to vec2 = Geom::Vector3d.new(vec)

@example

vector = Geom::Vector3d.new(1,0,0)
vector2 = vector.clone

@return [Geom::Vector3d] a Vector3d object which is the clone of

vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 255
def clone
end
cross(vector) click to toggle source

The {#cross} method is used to compute the cross product between two vectors.

The cross product, also called the vector product, is an operation on two vectors. The cross product of two vectors produces a third vector which is perpendicular to the plane in which the first two lie.

@example

vector1 = Geom::Vector3d.new(1,0,0)
vector2 = Geom::Vector3d.new(0,1,0)
vector3 = vector1 * vector2

@example

vector = Geom::Vector3d.new(1,0,0)
vector2 = Geom::Vector3d.new(0,1,0)
vector3 = vector.cross(vector2)

@param [Geom::Vector3d] vector

A Vector3d object.

@return [Geom::Vector3d] the cross of vector1 and vector2

@see *

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 282
def cross(vector)
end
dot(vector) click to toggle source

The {#dot} method is used to compute the dot product between two vectors.

@example

vector1 = Geom::Vector3d.new(0, 0, 1)
vector2 = Geom::Vector3d.new(0, 1, 0)
dot = vector1.dot(vector2)

@param [Geom::Vector] vector

@return [Float]

@see %

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 299
def dot(vector)
end
inspect() click to toggle source

The inspect method is used to inspect the contents of a vector as a friendly string.

@example

vector = Geom::Vector3d.new(0,0,1)
out_string = vector.inspect
puts out_string

@return [Geom::Vector3d] the Vector3d object

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 354
def inspect
end
length() click to toggle source

The length method is used to retrieve the length of the vector.

@example

vector = Geom::Vector3d.new(0,0,1)
l = vector.length

@return [Length] the length of the vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 366
def length
end
length=(length) click to toggle source

The length= method is used to set the length of the vector. The length must be greater than 0.

@example

vector = Geom::Vector3d.new(0,0,1)
l = vector.length
UI.messagebox(l)
newl = vector.length = 2

@param [Numeric] length

A length for the vector.

@return [Numeric] a newly set length

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 384
def length=(length)
end
normalize() click to toggle source

The normalize method is used to return a vector that is a unit vector of another.

@example

vector = Geom::Vector3d.new(0,0,2)
vector2 = vector.normalize

@return [Geom::Vector3d] a new normalized Vector3d object

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 397
def normalize
end
normalize!() click to toggle source

The normalize! method is used to convert a vector into a unit vector, in place.

Another way to do this is vec.length = 1

@example

vector = Geom::Vector3d.new(0,0,2)
vector.normalize!

@return [Geom::Vector3d] a normalized Vector3d object

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 412
def normalize!
end
parallel?(vector2) click to toggle source

The parallel method is used to determine if this vector is parallel to another vector to within tolerance.

@example

status = vector.parallel?(vector2)

@param [Geom::Vector3d] vector2

A Vector3d object.

@return [Boolean]

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 427
def parallel?(vector2)
end
perpendicular?(vector2) click to toggle source

The perpendicular? method is used to determine if this vector is perpendicular to another vector to within tolerance.

@example

vector = Geom::Vector3d.new(0,0,1)
vector2 = Geom::Vector3d.new(0,1,0)
status = vector.perpendicular?(vector2)

@param [Geom::Vector3d] vector2

A Vector3d object.

@return [Boolean]

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 444
def perpendicular?(vector2)
end
reverse() click to toggle source

The reverse method is used to return a new vector that is the reverse of this vector, while leaving the original unchanged.

@example

vector2 = vector.reverse

@return [Geom::Vector3d] a Vector3d object that is the reverse of

vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 457
def reverse
end
reverse!() click to toggle source

The reverse! method is used to reverse the vector in place.

@example

vector.reverse!

@return [Geom::Vector3d] a Vector3d object that is the reverse of

vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 469
def reverse!
end
samedirection?(vector2) click to toggle source

The samedirection? method is used to determine if this vector is parallel to and in the same direction as another vector to within tolerance.

@example

vector = Geom::Vector3d.new(0,0,1)
vector2 = Geom::Vector3d.new(0,1,0)
status = vector.samedirection?(vector2)

@param [Geom::Vector3d] vector2

A Vector3d object.

@return [Boolean]

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 486
def samedirection?(vector2)
end
set!(*args) click to toggle source

The set! method is used to set the coordinates of the vector.

@example This is a shortcut for writing:

vec.x = x
vec.y = y
vec.z = z

@example You may also call this method with an array or another vector:

vec.set!(x, y, z)
vec.set!([x, y, z])
vec.set!(vec2)

@example

vector = Geom::Vector3d.new(0,0,1)
vector.set! 1,0,0

@overload set!(array3d)

@param [Array(Numeric, Numeric, Numeric)] array3d
@return [Geom::Vector3d]

@overload set!(vector)

@param [Geom::Vector3d] vector
@return [Geom::Vector3d]

@overload set!(x, y, z)

@param [Numeric] x
@param [Numeric] y
@param [Numeric] z
@return [Geom::Vector3d]

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 523
def set!(*args)
end
to_a() click to toggle source

The to_a method retrieves the coordinates of the vector in an Array [x, y, z].

@example

a = vector.to_a

@return [Array(Length, Length, Length)] the coordinates of the vector in an array

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 535
def to_a
end
to_s() click to toggle source

The to_s method is used to format the vector as a String.

@example

vector = Geom::Vector3d.new(0,0,1)
out_string = vector.to_s
puts out_string

@return [String] a string representation of vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 548
def to_s
end
transform(transform) click to toggle source

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

@example

vector2 = vector.transform(transformation)

@param [Geom::Transformation] transform

A Transformation object to apply to the vector.

@return [Geom::Vector3d] the newly transformed vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 563
def transform(transform)
end
transform!(transform) click to toggle source

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

@example

vector.transform!(transformation)

@param [Geom::Transformation] transform

A Transformation object to apply to the vector.

@return [Geom::Vector3d] the transformed vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 577
def transform!(transform)
end
unitvector?() click to toggle source

The unitvector? method is used to see if the vector is a unit vector.

This is equivalent to vec.length == 1.0

@example

vector = Geom::Vector3d.new(0,0,1)
status = vector.unitvector?

@return [Boolean]

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 591
def unitvector?
end
valid?() click to toggle source

The valid? method is used to verify if a vector is valid. A vector is valid if its length is not zero.

@example

# A zero length vector will be invalid
vector = Geom::Vector3d.new(0,0,0)
status = vector.valid?
# A non-zero length vector is valid
vector = Geom::Vector3d.new(0,0,1)
status = vector.valid?

@return [Boolean]

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 608
def valid?
end
x() click to toggle source

The x method is used to retrieve the x coordinate of the vector.

@example

x = vector.x

@return [Length] the x coordinate of the vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 619
def x
end
x=(x) click to toggle source

The x= method is used to set the x coordinate of the vector.

@example

vector = Geom::Vector3d.new 1,2,3
x = vector.x = 10

@param [Numeric] x

The x coordinate for the vector.

@return [Numeric] the newly set x coordinate for the vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 634
def x=(x)
end
y() click to toggle source

The y method is used to retrieve the y coordinate of the vector.

@example

vector = Geom::Vector3d.new(1,2,3)
y = vector.y

@return [Length] the y coordinate of the vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 646
def y
end
y=(y) click to toggle source

Set the y coordinate of the vector.

@example

vector = Geom::Vector3d.new(1,2,3)
y = vector.y = 10

@param [Numeric] y

The y coordinate for the vector.

@return [Numeric] the newly set y coordinate for the vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 661
def y=(y)
end
z() click to toggle source

Get the z coordinate of the vector.

@example

vector = Geom::Vector3d.new(1,2,3)
z = vector.z

@return [Length] the z coordinate of the vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 673
def z
end
z=(z) click to toggle source

Set the z coordinate of the vector.

@example

vector = Geom::Vector3d.new(1,2,3)
z = vector.z = 10

@param [Numeric] z

The z coordinate for the vector.

@return [Numeric] the newly set z coordinate for the vector

@version SketchUp 6.0

# File lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb, line 688
def z=(z)
end