# Class: Geom::Vector3d

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

## Class Method Summary collapse

• Creates a new vector as a linear combination of two vectors.

## Instance Method Summary collapse

• Dot product.

• Computes the cross product between 2 Vectors.

• Vector subtraction.

• Compare two vectors coordinate by coordinate.

• Compare Vector3ds using SketchUp tolerance.

• Retrieves the coordinate of the vector at the specified index.

• Retrieves the coordinate of the vector at the specified index.

• Compute the angle between this vector and another vector.

• Compute an arbitrary set of orthogonal axes with this vector as the z-axis direction.

• Creates another vector identical to the vector being cloned.

• Computes the cross product between another vector.

• Compute the dot product between another vector.

• constructor

Creates a new 3D vector.

• Returns a string containing a human-readable representation of this vector.

• Retrieves the length of this vector.

• Sets length of this vector.

• Creates a copy of this vector that is a unit vector, that means its length is 1.

• Modifies this vector into a unit vector, that means this vector's length becomes 1.

• Determines whether this vector is parallel to another vector within tolerance.

• Determines whether this vector is perpendicular to another vector within tolerance.

• Creates a copy of this vector in the opposite direction of same length.

• Turns this vector in the opposite direction.

• Determines if this vector is parallel to and in the same direction as another vector to within tolerance.

• Sets the values of this vector.

• Returns an array representation of this vector.

• Returns a string representation of this vector.

• Applies a transformation to a copy this vector to create a new vector.

• Applies a transformation to this vector.

• Determines if this vector is a unit vector, that means if its length is 1.0.

• Verifies if this vector is valid.

• Retrieves the x coordinate of this vector.

• Sets the x value of this vector.

• Retrieves the y coordinate of this vector.

• Sets the y value of this vector.

• Retrieves the z coordinate of this vector.

• Sets the z value of this vector.

## Constructor Details

### #initialize ⇒ Vector3d #initialize(vector) ⇒ Vector3d #initialize(array) ⇒ Vector3d #self.new(x, y, z = 0.0) ⇒ Vector3d

Creates a new 3D vector.

• #initializeVector3d

Creates a vector with all coordinates set to zero. Note that such a zero-length vector is not valid.

 ``` 15 16``` ```# File 'lib/vector3d.rb', line 15 def initialize(*args) end```

## Class Method Details

### .linear_combination(weight1, vector1, weight2, vector2) ⇒ Geom::Vector3d

Creates a new vector as a linear combination of two vectors. This method is generally used to get a vector at some percentage along a line connecting the two vectors. The weights should sum up to 1 if you want to get a on that line. The weights should be between 0 and 1 if you want to get a vector between the two vectors.

 ``` 130 131``` ```# File 'lib/vector3d.rb', line 130 def self.linear_combination(weight1, vector1, weight2, vector2) end```

## Instance Method Details

### #%(vector) ⇒ Float

Dot product.

 ``` 21 22``` ```# File 'lib/vector3d.rb', line 21 def %(vector) end```

### #*(vector) ⇒ Geom::Vector3d

Computes the cross product between 2 Vectors. The cross product of two vectors produces a third vector which is perpendicular to the plane in which the first two lie.

 ``` 29 30``` ```# File 'lib/vector3d.rb', line 29 def *(vector) end```

### #+(vector) ⇒ Geom::Vector3d

 ``` 35 36``` ```# File 'lib/vector3d.rb', line 35 def +(vector) end```

### #-(vector) ⇒ Geom::Vector3d

Vector subtraction

 ``` 41 42``` ```# File 'lib/vector3d.rb', line 41 def -(vector) end```

### #<(vector) ⇒ Boolean

Compare two vectors coordinate by coordinate. First the x coordinates are compared, if they are equal, the y coordinates are compared, if those are equal finally the z coordinates.

Examples:

``````v1 = Geom::Vector3d.new(10, 10, 90)
v2 = Geom::Vector3d.new(10, 20, 20)
v1 < v2 # ==> true``````
 ``` 52 53``` ```# File 'lib/vector3d.rb', line 52 def <(vector) end```

### #==(vector) ⇒ Boolean

Compare Geom::Vector3ds using SketchUp tolerance.

 ``` 58 59``` ```# File 'lib/vector3d.rb', line 58 def ==(vector) end```

### #[](index) ⇒ Numeric

Retrieves the coordinate of the vector at the specified index.

Raises:

• IndexError Raised if the index is outside the range [0,2]. Note that negative indices [-3,-1] don't raise.

 ``` 65 66``` ```# File 'lib/vector3d.rb', line 65 def [](index) end```

### #[]=(index, value) ⇒ Numeric

Retrieves the coordinate of the vector at the specified index.

Raises:

• IndexError Raised if the index is outside the range [0,2]. Note that negative indices [-3,-1] don't raise.

 ``` 73 74``` ```# File 'lib/vector3d.rb', line 73 def []=(index, value) end```

### #angle_between(vector) ⇒ Float

Compute the angle between this vector and another vector.

 ``` 79 80``` ```# File 'lib/vector3d.rb', line 79 def angle_between(vector) end```

### #axes ⇒ Array(Geom::Vector3d,Geom::Vector3d,Geom::Vector3d)

Compute an arbitrary set of orthogonal axes with this vector as the z-axis direction. If possible, the vector's x-axis is the up vector, being in plane with the global z-axis.

 ``` 86 87``` ```# File 'lib/vector3d.rb', line 86 def axes end```

### #clone ⇒ Geom::Vector3d

Creates another vector identical to the vector being cloned.

 ``` 91 92``` ```# File 'lib/vector3d.rb', line 91 def clone end```

### #cross(vector) ⇒ Geom::Vector3d

Computes the cross product between another vector. The cross product of two vectors produces a third vector which is perpendicular to the plane in which the first two lie.

 ``` 99 100``` ```# File 'lib/vector3d.rb', line 99 def cross(vector) end```

### #dot(vector) ⇒ Object

Compute the dot product between another vector.

 ``` 103 104``` ```# File 'lib/vector3d.rb', line 103 def dot(vector) end```

### #inspect ⇒ String

Returns a string containing a human-readable representation of this vector.

 ``` 108 109``` ```# File 'lib/vector3d.rb', line 108 def inspect end```

### #length ⇒ Length

Retrieves the length of this vector.

 ``` 113 114``` ```# File 'lib/vector3d.rb', line 113 def length end```

### #length=(value) ⇒ Numeric

Sets length of this vector.

 ``` 119 120``` ```# File 'lib/vector3d.rb', line 119 def length=(value) end```

### #normalize ⇒ Geom::Vector3d

Creates a copy of this vector that is a unit vector, that means its length is 1.

 ``` 135 136``` ```# File 'lib/vector3d.rb', line 135 def normalize end```

### #normalize! ⇒ self

Modifies this vector into a unit vector, that means this vector's length becomes 1.

 ``` 140 141``` ```# File 'lib/vector3d.rb', line 140 def normalize! end```

### #parallel?(vector) ⇒ Boolean

Determines whether this vector is parallel to another vector within tolerance. The vectors may have different length and be reversed but would still be parallel.

 ``` 147 148``` ```# File 'lib/vector3d.rb', line 147 def parallel?(vector) end```

### #perpendicular?(vector) ⇒ Boolean

Determines whether this vector is perpendicular to another vector within tolerance.

 ``` 153 154``` ```# File 'lib/vector3d.rb', line 153 def perpendicular?(vector) end```

### #reverse ⇒ Geom::Vector3d

Creates a copy of this vector in the opposite direction of same length.

 ``` 158 159``` ```# File 'lib/vector3d.rb', line 158 def reverse end```

### #reverse! ⇒ self

Turns this vector in the opposite direction. This is the same as multiplying its length with -1.

 ``` 163 164``` ```# File 'lib/vector3d.rb', line 163 def reverse! end```

### #samedirection?(vector) ⇒ Boolean

Determines if this vector is parallel to and in the same direction as another vector to within tolerance.

 ``` 169 170``` ```# File 'lib/vector3d.rb', line 169 def samedirection?(vector) end```

### #set!(x, y = self.x, z = self.y) ⇒ self

Sets the values of this vector.

 ``` 177 178``` ```# File 'lib/vector3d.rb', line 177 def set!(x, y=self.x, z=self.y) end```

### #to_a ⇒ Array(Length,Length,Length)

Returns an array representation of this vector.

 ``` 182 183``` ```# File 'lib/vector3d.rb', line 182 def to_a end```

### #to_s ⇒ String

Returns a string representation of this vector.

 ``` 187 188``` ```# File 'lib/vector3d.rb', line 187 def to_s end```

### #transform(transformation) ⇒ Geom::Vector3d

Applies a transformation to a copy this vector to create a new vector.

 ``` 193 194``` ```# File 'lib/vector3d.rb', line 193 def transform(transformation) end```

### #transform!(transformation) ⇒ self

Applies a transformation to this vector. Unlike the #transform method, the vector itself is modified.

 ``` 200 201``` ```# File 'lib/vector3d.rb', line 200 def transform!(transformation) end```

### #unitvector? ⇒ Boolean

Determines if this vector is a unit vector, that means if its length is 1.0.

 ``` 205 206``` ```# File 'lib/vector3d.rb', line 205 def unitvector? end```

### #valid? ⇒ Boolean

Verifies if this vector is valid. A vector is valid if its length is not zero.

 ``` 210 211``` ```# File 'lib/vector3d.rb', line 210 def valid? end```

### #x ⇒ Float

Retrieves the x coordinate of this vector.

 ``` 215 216``` ```# File 'lib/vector3d.rb', line 215 def x end```

### #x=(value) ⇒ Numeric

Sets the x value of this vector.

 ``` 221 222``` ```# File 'lib/vector3d.rb', line 221 def x=(value) end```

### #y ⇒ Float

Retrieves the y coordinate of this vector.

 ``` 226 227``` ```# File 'lib/vector3d.rb', line 226 def y end```

### #y=(value) ⇒ Numeric

Sets the y value of this vector.

 ``` 232 233``` ```# File 'lib/vector3d.rb', line 232 def y=(value) end```

### #z ⇒ Float

Retrieves the z coordinate of this vector.

 ``` 237 238``` ```# File 'lib/vector3d.rb', line 237 def z end```

### #z=(value) ⇒ Numeric

Sets the z value of this vector.

 ``` 243 244``` ```# File 'lib/vector3d.rb', line 243 def z=(value) end```