Package Scientific :: Package Geometry :: Class Vector

[frames] | no frames]

# Class Vector

Vector in 3D space

Constructor:

Vectors support the usual arithmetic operations ('v1', 'v2': vectors, 's': scalar):

- 'v1+v2' (addition)
- 'v1-v2' (subtraction)
- 'v1*v2' (scalar product)
- 's*v1', 'v1*s' (multiplication with a scalar)
- 'v1/s' (division by a scalar)

The three coordinates can be extracted by indexing.

Vectors are immutable, i.e. their elements cannot be changed.

Vector elements can be any objects on which the standard arithmetic operations plus the functions sqrt and arccos are defined.

Instance Methods

__add__(self, other) |

__cmp__(self, other) |

__copy__(self, memo=None) |

__deepcopy__(self, memo=None) |

__div__(self, other) |

__getitem__(self, index) |

__getstate__(self) |

__init__(self, x=None, y=None, z=None) There are two supported calling patterns: |

__len__(self) |

__mul__(self, other) |

__neg__(self) |

__radd__(self, other) |

__rdiv__(self, other) |

__repr__(self) |

__rmul__(self, other) |

__rsub__(self, other) |

__setstate__(self, state) |

__str__(self) |

__sub__(self, other) |

`float`

angle(self, other) Returns: the angle to other |

Scientific.Geometry.Tensor

asTensor(self) Returns: an equivalent rank-1 tensor object |

Vector

cross(self, other) Returns: cross product with other |

Scientific.Geometry.Tensor

dyadicProduct(self, other) Returns: the dyadic product with other |

type of vector elements

length(self) Returns: the length (norm) of the vector |

Vector

normal(self) Returns: a normalized (length 1) copy of the vector |

type of vector elements

x(self) Returns: the x coordinate |

type of vector elements

y(self) Returns: the y coordinate |

type of vector elements

z(self) Returns: the z coordinate |

Class Variables
| is_vector = `1`

Method Details

### __init__(self, x=None, y=None, z=None)
(Constructor)

There are two supported calling patterns:

1. `Vector(x, y, z)` (from three coordinates)
2. `Vector(coordinates)` (from any sequence containing three coordinates)

### angle(self, other)

Parameters:
  - `other` (Vector) - a vector
Returns: `float`
  the angle to other
Raises:
  - `TypeError` - if other is not a vector

### asTensor(self)

Returns: Scientific.Geometry.Tensor
  an equivalent rank-1 tensor object

### cross(self, other)

Parameters:
  - `other` (Vector) - a vector
Returns: Vector
  cross product with other

### dyadicProduct(self, other)

Parameters:
  - `other` (Vector or Scientific.Geometry.Tensor) - a vector or a tensor
Returns: Scientific.Geometry.Tensor
  the dyadic product with other
Raises:
  - `TypeError` - if other is not a vector or a tensor

### length(self)

Returns: type of vector elements
  the length (norm) of the vector

### normal(self)

Returns: Vector
  a normalized (length 1) copy of the vector
Raises:
  - `ZeroDivisionError` - if vector length is zero

### x(self)

Returns: type of vector elements
  the x coordinate

### y(self)

Returns: type of vector elements
  the y coordinate

### z(self)

Returns: type of vector elements
  the z coordinate