Class: Geom::Vector3d

Inherits:
Object
  • Object
show all
Defined in:
lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeom::Vector3d #initialize(x, y, z) ⇒ Geom::Vector3d #initialize(array3d) ⇒ Geom::Vector3d #initialize(array2d) ⇒ Geom::Vector3d #initialize(vector) ⇒ Geom::Vector3d

The new method is used to create a new vector.

Examples:

# 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

Overloads:

Version:

  • SketchUp 6.0



342
343
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 342

def initialize(*args)
end

Class Method Details

.linear_combination(weight1, vector1, weight2, vector2) ⇒ Geom::Vector3d .linear_combination(x, xaxis, y, yaxis, z, zaxis) ⇒ Geom::Vector3d

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.

Examples:

# 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)

Overloads:

Version:

  • SketchUp 6.0



47
48
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 47

def self.linear_combination(*args)
end

Instance Method Details

#%(vector) ⇒ Float

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

This is an alias of the #dot method.

Examples:

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

Parameters:

Returns:

  • (Float)

See Also:

Version:

  • SketchUp 6.0



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

def %(vector)
end

#*(vector) ⇒ Geom::Vector3d

The #* 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.

This is an alias of the #cross method.

Examples:

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

Parameters:

Returns:

See Also:

Version:

  • SketchUp 6.0



96
97
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 96

def *(vector)
end

#+(vector2) ⇒ Geom::Vector3d

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

Examples:

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

Parameters:

  • vector2

    A Vector3d object.

Returns:

Version:

  • SketchUp 6.0



112
113
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 112

def +(vector2)
end

#-(vector2) ⇒ Geom::Vector3d

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

Examples:

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

Parameters:

  • vector2

    A Vector3d object.

Returns:

Version:

  • SketchUp 6.0



128
129
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 128

def -(vector2)
end

#<(vector2) ⇒ Boolean

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.

Examples:

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

Parameters:

  • vector2

    A Vector3d object.

Returns:

  • (Boolean)

    true if the vector’s x, y or z component is less

Version:

  • SketchUp 6.0



145
146
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 145

def <(vector2)
end

#==(vector2) ⇒ Boolean

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

Examples:

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

Parameters:

  • vector2

    A Vector3d object.

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0



164
165
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 164

def ==(vector2)
end

#[](i) ⇒ Length

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:

Examples:

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

Parameters:

  • i (Integer)

    An index into an array of three coordinates.

Returns:

  • (Length)

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

Version:

  • SketchUp 6.0



191
192
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 191

def [](i)
end

#[]=(index, value) ⇒ Numeric

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.

Examples:

vector[i] = coordinate

Parameters:

  • index (Integer)

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

  • value (Numeric)

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

Returns:

  • (Numeric)

    the newly set coordinate value

Version:

  • SketchUp 6.0



209
210
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 209

def []=(index, value)
end

#angle_between(vector2) ⇒ Float

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

Examples:

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

Parameters:

Returns:

  • (Float)

    an angle (in radians)

Version:

  • SketchUp 6.0



226
227
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 226

def angle_between(vector2)
end

#axesArray(Geom::Vector3d, Geom::Vector3d, Geom::Vector3d)

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]

Vector3d objects

Examples:

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

Returns:

Version:

  • SketchUp 6.0



243
244
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 243

def axes
end

#cloneGeom::Vector3d

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

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

Examples:

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

Returns:

Version:

  • SketchUp 6.0



258
259
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 258

def clone
end

#cross(vector) ⇒ Geom::Vector3d

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.

Examples:

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

Parameters:

Returns:

See Also:

Version:

  • SketchUp 6.0



284
285
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 284

def cross(vector)
end

#dot(vector) ⇒ Float

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

Examples:

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

Parameters:

Returns:

  • (Float)

See Also:

Version:

  • SketchUp 6.0



301
302
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 301

def dot(vector)
end

#inspectGeom::Vector3d

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

Examples:

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

Returns:

Version:

  • SketchUp 6.0



356
357
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 356

def inspect
end

#lengthLength

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

Examples:

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

Returns:

  • (Length)

    the length of the vector

Version:

  • SketchUp 6.0



368
369
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 368

def length
end

#length=(length) ⇒ Numeric

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

Examples:

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

Parameters:

  • length (Numeric)

    A length for the vector.

Returns:

Version:

  • SketchUp 6.0



386
387
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 386

def length=(length)
end

#normalizeGeom::Vector3d

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

Examples:

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

Returns:

Version:

  • SketchUp 6.0



399
400
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 399

def normalize
end

#normalize!Geom::Vector3d

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

Another way to do this is vec.length = 1

Examples:

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

Returns:

Version:

  • SketchUp 6.0



414
415
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 414

def normalize!
end

#parallel?(vector2) ⇒ Boolean

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

Examples:

status = vector.parallel?(vector2)

Parameters:

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0



429
430
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 429

def parallel?(vector2)
end

#perpendicular?(vector2) ⇒ Boolean

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

Examples:

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

Parameters:

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0



446
447
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 446

def perpendicular?(vector2)
end

#reverseGeom::Vector3d

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

Examples:

vector2 = vector.reverse

Returns:

  • (Geom::Vector3d)

    a Vector3d object that is the reverse of vector

Version:

  • SketchUp 6.0



459
460
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 459

def reverse
end

#reverse!Geom::Vector3d

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

Examples:

vector.reverse!

Returns:

  • (Geom::Vector3d)

    a Vector3d object that is the reverse of vector

Version:

  • SketchUp 6.0



471
472
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 471

def reverse!
end

#samedirection?(vector2) ⇒ Boolean

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

Examples:

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

Parameters:

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0



488
489
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 488

def samedirection?(vector2)
end

#set!(array3d) ⇒ Geom::Vector3d #set!(vector) ⇒ Geom::Vector3d #set!(x, y, z) ⇒ Geom::Vector3d

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

Examples:

This is a shortcut for writing:

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

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)
vector = Geom::Vector3d.new(0,0,1)
vector.set! 1,0,0

Overloads:

Version:

  • SketchUp 6.0



525
526
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 525

def set!(*args)
end

#to_aArray(Length, Length, Length)

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

Examples:

a = vector.to_a

Returns:

Version:

  • SketchUp 6.0



537
538
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 537

def to_a
end

#to_sString

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

Examples:

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

Returns:

  • (String)

    a string representation of vector

Version:

  • SketchUp 6.0



550
551
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 550

def to_s
end

#transform(transform) ⇒ Geom::Vector3d

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

Examples:

vector2 = vector.transform(transformation)

Parameters:

Returns:

Version:

  • SketchUp 6.0



565
566
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 565

def transform(transform)
end

#transform!(transform) ⇒ Geom::Vector3d

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

Examples:

vector.transform!(transformation)

Parameters:

Returns:

Version:

  • SketchUp 6.0



579
580
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 579

def transform!(transform)
end

#unitvector?Boolean

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

This is equivalent to vec.length == 1.0

Examples:

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

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0



593
594
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 593

def unitvector?
end

#valid?Boolean

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

Examples:

# 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?

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0



610
611
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 610

def valid?
end

#xLength

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

Examples:

x = vector.x

Returns:

  • (Length)

    the x coordinate of the vector

Version:

  • SketchUp 6.0



621
622
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 621

def x
end

#x=(x) ⇒ Numeric

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

Examples:

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

Parameters:

  • x (Numeric)

    The x coordinate for the vector.

Returns:

  • (Numeric)

    the newly set x coordinate for the vector

Version:

  • SketchUp 6.0



636
637
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 636

def x=(x)
end

#yLength

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

Examples:

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

Returns:

  • (Length)

    the y coordinate of the vector

Version:

  • SketchUp 6.0



648
649
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 648

def y
end

#y=(y) ⇒ Numeric

Set the y coordinate of the vector.

Examples:

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

Parameters:

  • y (Numeric)

    The y coordinate for the vector.

Returns:

  • (Numeric)

    the newly set y coordinate for the vector

Version:

  • SketchUp 6.0



663
664
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 663

def y=(y)
end

#zLength

Get the z coordinate of the vector.

Examples:

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

Returns:

  • (Length)

    the z coordinate of the vector

Version:

  • SketchUp 6.0



675
676
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 675

def z
end

#z=(z) ⇒ Numeric

Set the z coordinate of the vector.

Examples:

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

Parameters:

  • z (Numeric)

    The z coordinate for the vector.

Returns:

  • (Numeric)

    the newly set z coordinate for the vector

Version:

  • SketchUp 6.0



690
691
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector3d.rb', line 690

def z=(z)
end