This document is for OpenStructure version 1.8, the latest version is 2.9.0 !

Vectors

The Vec2, Vec3, Vec4 classes implement vectors in 2, 3 and four dimensions. They support basic arithmetic via overloaded operators. Essentially, the following basic operations are available:

  • adding and subtracting two vectors
  • negation
  • multiplying and dividing by scalar value

This is shown in the following example:

vec_a=geom.Vec2(1, 0)
vec_b=geom.Vec2(0, 1)
print vec_a, vec_b
print vec_a+vec_b
print vec_a*3-vec_b

The standard vector operations are implemented as free standing functions:

vec_a=geom.Vec3(1, 0, 0)
vec_b=geom.Vec3(0, 1, 0)

print geom.Dot(vec_a, vec_b)
print geom.Cross(vec_a, vec_b)

print geom.Normalize(geom.Vec3(1, 1, 0))

print geom.Length(geom.Vec3(1, 1, 1))

Vector Classes

class Vec2([x=0.0, y=0.0, z=0.0])
class Vec2(vec)

Real-valued vector in 2 dimensions.

Parameters:
  • x (float or int) – x coordinate
  • y (float or int) – y coordinate
  • vec (Vec2, Vec3 or Vec4) – the coordinates are set to the coordinates of vec. If vec is a Vec2, the coordinates are copied directly, If vec is a Vec3, the x and y coordinates are set to the coordinates of vec and z is silently swallowed. If vec is of type Vec4, x and y are divided by the homogenous coordinate w, raising a DivideByZeroException when w is zero.
x

The x-coordinate of the vector.

Type:float
y

The y-coordinate of the vector.

class Vec3([x=0.0, y=0.0, z=0.0])
class Vec3(vec)

Real-valued vector in 3 dimensions.

Parameters:
  • x – x coordinate
  • y – y coordinate
  • z – z coordinate
  • vec (Vec2, Vec3 or Vec4) – the coordinates are set to the coordinates of vec. If vec is a Vec3, the coordinates are copied directly, If vec is a Vec2, the x and y coordinates are set to the coordinates of vec and z is initialized to zero. If vec is of type Vec4, x, y and z are divided by homogenous coordinate w, raising a DivideByZeroException when w is zero.
x

The x-coordinate of the vector.

Type:float or int
y

The y-coordinate of the vector.

Type:float or int
z

The z-coordinate of the vector.

Type:float or int
class Vec4([x=0.0, y=0.0, z=0.0, w=1.0])
class Vec4(vec)

Real-valued vector in 4 dimensions.

Parameters:
  • x (float or int) – x coordinate
  • y (float or int) – y coordinate
  • z (float or int) – z coordinate
  • w (float or int) – w (homogenous) coordinate
  • vec – the coordinates are set to the coordinates of vec. If vec is a Vec4, the coordinates are copied directly, If vec is a Vec2, the x and y coordinates are set to the coordinates of vec and z and w are initialized to 0 and 1, respectively. If vec is of type Vec4, x, y and z are divided by homogenous coordinate w, raising a DivideByZeroException when w is zero.
x

The x-coordinate of the vector.

Type:float or int
y

The y-coordinate of the vector.

Type:float or int
z

The z-coordinate of the vector.

Type:float or int
w

The homogenous coordinate.

Type:float or int

Functions Operating on Vectors

Cross(vec_a, vec_b)

Cross product of vec_a and vec_b

Dot(vec_a, vec_b)

Dot (scalar) product of vec_a and vec_b

Parameters:
  • vec_a (Vec3) – first vector
  • vec_b (Vec3) – second vector
Length(vec)

Length of vector

Parameters:vec (Vec2, Vec3 or Vec4) –
Length2(vec)

Returns the squared length of vec

Parameters:vec (Vec2, Vec3 or Vec4) –
Normalize(vec)

Returns a normalized version of vec

Parameters:vec (Vec2, Vec3 or Vec4) – Vector to be normalized

Search

Enter search terms or a module, class or function name.

Contents

Documentation is available for the following OpenStructure versions:

dev / 2.9.0 / 2.8 / 2.7 / 2.6 / 2.5 / 2.4 / 2.3.1 / 2.3 / 2.2 / 2.1 / 2.0 / 1.9 / (Currently viewing 1.8) / 1.7.1 / 1.7 / 1.6 / 1.5 / 1.4 / 1.3 / 1.2 / 1.11 / 1.10 / 1.1

This documentation is still under heavy development!
If something is missing or if you need the C++ API description in doxygen style, check our old documentation for further information.