My favorites | English | Sign in

Faster apps faster - GWT 2.0 with Speed Tracer New!

Google SketchUp Ruby API

Vector3d

class

Parent: Object

Introduction

SketchUp 6.0+

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.

Methods

Vector3d.%SketchUp 6.0+

The % method is used to compute the dot product between two vectors. This is an alias of the dot method.

Arguments:

vector2
A Vector3d object.

Returns:

d
the dot product of vector1 and vector2
 vector = Geom::Vector3d.new 0,0,1
 vector2 = Geom::Vector3d.new 0,1,0
 d = vector.dot vector2

Vector3d.*SketchUp 6.0+

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.

Arguments:

vector1
A Vector3d object.
vector2
A Vector3d object.

Returns:

vector
a Vector3d object if successful
 vector = Geom::Vector3d.new 1,0,0
 vector2 = Geom::Vector3d.new 0,1,0

Vector3d.+SketchUp 6.0+

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

Arguments:

vector2
A Vector3d object.

Returns:

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

Vector3d.-SketchUp 6.0+

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

Arguments:

vector2
A Vector3d object.

Returns:

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

Vector3d.<SketchUp 6.0+

The < method is used to determine if a vector is less than another.

Arguments:

vector2
A Vector3d object.

Returns:

true if it is less
 vector = Geom::Vector3d.new 0,0,2
 vector2 = Geom::Vector3d.new 0,1,0
 lt = vector < vector2

Vector3d.==SketchUp 6.0+

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

Arguments:

vector1
A Vector3d object.
vector2
A Vector3d object.

Returns:

status
true if vector1 is equal to vector 2. False if they are not equal.
 vector = Geom::Vector3d.new 1,0,0
 vector2 = Geom::Vector3d.new 0,1,0
 status = vector == vector2
 # Returns false
 UI.messagebox status

Vector3d.[]SketchUp 6.0+

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:

Arguments:

i
An index into an array of three coordinates.

Returns:

coordinate
the value for the x, y, or z coordinate.
 vector = Geom::Vector3d.new 1,0,0
 value = vector[0]
 if (value)
   UI.messagebox value
 else
   UI.messagebox "Failure"
 end

Vector3d.[]=SketchUp 6.0+

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.

Arguments:

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

Returns:

value
the newly set coordinate value
 value = vector[i] = coordinate

Vector3d.angle_betweenSketchUp 6.0+

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

Arguments:

vector2
A Vector3d object.

Returns:

angle
an angle (in radians)
 angle = vector.angle_between vector2

Vector3d.axesSketchUp 6.0+

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]

Returns:

a
an Array object containing three Vector3d objects
 vector = Geom::Vector3d.new 1,0,0
 a = vector.axes

Vector3d.cloneSketchUp 6.0+

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

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

Returns:

vector2
a Vector3d object which is the clone of vector
 vector = Geom::Vector3d.new 1,0,0
 vector2 = vector.clone

Vector3d.crossSketchUp 6.0+

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.

Arguments:

vector2
A Vector3d object.

Returns:

vector
the cross of vector1 and vector2
 vector = Geom::Vector3d.new 1,0,0
 vector2 = Geom::Vector3d.new 0,1,0
 v = vector.cross vector2

Vector3d.dotSketchUp 6.0+

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

Arguments:

vector2
A Vector3d object.

Returns:

d
the dot product of vector1 and vector2
 vector = Geom::Vector3d.new 0,0,1
 vector2 = Geom::Vector3d.new 0,1,0
 d = vector.dot vector2

Vector3d.inspectSketchUp 6.0+

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

Returns:

vector
the Vector3d object
 vector = vector.inspect

Vector3d.lengthSketchUp 6.0+

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

Returns:

length
the length of the vector
 vector = Geom::Vector3d.new 0,0,1
 l = vector.length

Vector3d.length=SketchUp 6.0+

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

Arguments:

length
A length for the vector.

Returns:

length
a newly set length
 vector = Geom::Vector3d.new 0,0,1
 l = vector.length
 UI.messagebox l
 newl = vector.length = 2

Vector3d.linear_combinationSketchUp 6.0+

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 point = weight1 * point1 + weight2 * point2.

In addition to the 4-argument form detailed here, you may also call this method with 6 parameters in the form of:

  • vec = Geom::Vector3d.linear_combination(x, xaxis, y, yaxis, z, zaxis)
  • Arguments:

    weight1
    A weight or percentage.
    vector1
    The first vector.
    weight2
    A weight or percentage.
    vector2
    The end point of the line.

    Returns:

    vector
    a Vector3d object
     # 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)

Vector3d.newSketchUp 6.0+

The new method is used to create a new vector. Typically you call this by passing an x, y, and z value, but you may also call it in any of the following forms:

  • vec = Geom::Vector3d.new
  • vec = Geom::Vector3d.new(x, y, z)
  • vec = Geom::Vector3d.new(vec2)
  • Arguments:

    x
    A X value.
    y
    A Y value.
    z
    A Z value.
    vector2
    A Vector3d object.

    Returns:

    vector
    a vector3d object
     # 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

Vector3d.normalizeSketchUp 6.0+

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

Returns:

vector2
a normalized Vector3d object
 vector = Geom::Vector3d.new 0,0,1
 vector2 = vector.normalize

Vector3d.normalize!SketchUp 6.0+

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

Another way to do this is vec.length = 1

Returns:

vector2
a normalized Vector3d object
 vector = Geom::Vector3d.new 0,0,1
 vector.normalize!

Vector3d.parallel?SketchUp 6.0+

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

Arguments:

vector2
A Vector3d object.

Returns:

status
true if vector and vector2 are parallel. False if they are not parallel.
 status = vector.parallel? vector2

Vector3d.perpendicular?SketchUp 6.0+

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

Arguments:

vector2
A Vector3d object.

Returns:

status
true if vector and vector2 are parallel. False if they are not parallel.
 vector = Geom::Vector3d.new 0,0,1
 vector2 = Geom::Vector3d.new 0,1,0
 status = vector.perpendicular? vector2

Vector3d.reverseSketchUp 6.0+

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

Returns:

vector2
a Vector3d object that is the reverse of vector
 vector2 = vector.reverse

Vector3d.reverse!SketchUp 6.0+

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

Returns:

vector2
a Vector3d object that is the reverse of vector
 vector.reverse!

Vector3d.samedirection?SketchUp 6.0+

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

Arguments:

vector2
A Vector3d object.

Returns:

status
true if vector and vector2 are in the same direction. False if they are not in the same direction.
 vector = Geom::Vector3d.new 0,0,1
 vector2 = Geom::Vector3d.new 0,1,0
 status = vector.sime_direction? vector2

Vector3d.set!SketchUp 6.0+

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

This is a shortcut for writing:

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

Arguments:

x
The x value for the vector.
y
The y value for the vector.
z
The z value for the vector.
vector2
A Vector3d object.

Returns:

vector
The newly set Vector3d object
 vector = Geom::Vector3d.new 0,0,1
 vector2 = vector.set! 1,0,0

Vector3d.to_aSketchUp 6.0+

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

Returns:

a
the coordinates of the vector in an array
 a = vector.to_a

Vector3d.to_sSketchUp 6.0+

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

Returns:

s
a string representation of vector
 vector = Geom::Vector3d.new 0,0,1
 string = vector.to_s

Vector3d.transformSketchUp 6.0+

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

Arguments:

transform
A Transformation object to apply to the vector.

Returns:

vector2
the newly transformed vector
 vector2 = vector.transform! transformation

Vector3d.transform!SketchUp 6.0+

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

Arguments:

transform
A Transformation object to apply to the vector.

Returns:

vector
the vector
 vector.transform! transformation

Vector3d.unitvector?SketchUp 6.0+

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

This is equivalent to vec.length == 1.0

Returns:

status
true if the vector is a unit vector. False if the vector is not a unit vector.
 vector = Geom::Vector3d.new 0,0,1
 status = vector.unitvector

Vector3d.valid?SketchUp 6.0+

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

Returns:

status
true if the vector is valid. false if the vector is not valid.
 status = vector.valid

Vector3d.xSketchUp 6.0+

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

Returns:

x
the x coordinate of the vector
 x = vector.x

Vector3d.x=SketchUp 6.0+

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

Arguments:

x
The x coordinate for the vector.

Returns:

x
the newly set x coordinate for the vector
 vector = Geom::Vector3d.new 1,2,3
 x = vector.x = 10

Vector3d.ySketchUp 6.0+

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

Returns:

y
the y coordinate of the vector
 vector = Geom::Vector3d.new 1,2,3
 y = vector.y

Vector3d.y=SketchUp 6.0+

Set the y coordinate of the vector.

Arguments:

y
The y coordinate for the vector.

Returns:

y
the newly set y coordinate for the vector
 vector = Geom::Vector3d.new 1,2,3
 y = vector.y = 10

Vector3d.zSketchUp 6.0+

Get the z coordinate of the vector.

Returns:

z
the z coordinate of the vector
 vector = Geom::Vector3d.new 1,2,3
 z = vector.z

Vector3d.z=SketchUp 6.0+

Set the z coordinate of the vector.

Arguments:

z
The z coordinate for the vector.

Returns:

z
the newly set z coordinate for the vector
 vector = Geom::Vector3d.new 1,2,3
 z = vector.z = 10