# class Vector

Cuby's implementation of vector algebra and basic 3D geometry in Vector class.

Access to the object can be locked using Locking module, all methods are locked

This is pure ruby implementation, in contrast to math_vector which uses binary library. It is intended as a replacement where the performance is not crucial, but portability is.

### Initializators

self.from_array(array) # new instance of the class

Creates new vector from array

```v1 = Vector.from_array([1.0, 0.0, 0.0])
v2 = Vector.from_array(some_array)
```

self.of_size(size,fill=0.0) # new instance of the class

Creates new vector of given size filled with number fill

```Vector.of_size(5,1.0)
=> Vector: [1.0,1.0,1.0,1.0,1.0]
```

self.zero(size) # new instance of the class

Creates new vector of given size filled with zeroes

```Vector.of_size(5)
=> Vector: [0.0,0.0,0.0,0.0,0.0]
```

### Basics

size # Fixnum

Returns size of the vector

```Vector[1.0, 0.0, 0.0].size
=> 3
```

deep_copy # Vector

deep copy

### Element access

[](index) # Float

Returns selected element

[]=(index,value) # Float (value written)

Write to selected element

subvector(first, size) # => Vector

### Type conversion

to_a # Array of Floats

Converts Vector to Array

to_matrix # Matrix

Converts Vector to column Matrix

### Operators: vector - vector

+(vector) # Vector

-(vector) # Vector

Vector subtraction

plus!(vector) # nil

In-place vector addition, faster than using a = a + b

minus!(vector) # nil

In-place vector subtraction, faster than using a = a - b

dot(vector) # Float

Dot product, synonym to dot_product

elementwise_multiply(vector) # => Vector

elementwise_divide(vector) # => Vector

### Operators: vector - something else

comutative_multiply(operand)

this method is equivalent to * operator, but is used by the numerical types extension found in algebra.rb

### Comparison

== (vector) # true | false

=~ (vector) # true | false

Loose comparison of two vectors, element by element. Max. allowed error is stored in class variable, accessible by methods self.epsilon and self.epsilon= .

### Misc

sum

abs # Float

Absolute value (size) of vector

max

min

max_abs

min_abs

normalize # Vector

Returns normalized vector

normalize! # nil

In-place version of normalize