class Vec

Overview

A 3-vector useful for postions etc. More…

#include <Vec.h>
 
class Vec {
public:
    // fields
 
    double x[3];
 
    // construction
 
    Vec();
    Vec(double x0, double x1, double x2);
 
    // methods
 
    double operator*(const Vec& v) const;
    Vec operator*(const double& s) const;
    Vec operator+(const Vec& v) const;
    Vec operator-(const Vec& v) const;
    Vec operator-() const;
    Vec& operator+=(const Vec& v);
    Vec& operator-=(const Vec& v);
    Vec& operator*=(double s);
    Vec& operator/=(double s);
    double operator[](int n) const;
    double& operator[](int n);
};

Detailed Documentation

A 3-vector useful for postions etc.

The only data is the three positions (and there are no virtual functions), so the memory layout of an array of Vecs will be x0, y0, z0, x1, y1, z1, x2, …

Almost all operations are inline for speed.

Fields

double x[3]

The actual data.

Construction

Vec()

Dummy constructor needed by STL containers.

Vec(double x0, double x1, double x2)

Construct a 3-vector from three doubles.

Methods

double operator*(const Vec& v) const

Dot product.

Vec operator*(const double& s) const

Multiplication with scalar.

Vec operator+(const Vec& v) const

Add two Vecs.

Vec operator-(const Vec& v) const

Subtract two Vecs.

Vec operator-() const

Unary minus.

Vec& operator+=(const Vec& v)

Add a Vec to this one.

Vec& operator-=(const Vec& v)

Subtract a vec from this one.

Vec& operator*=(double s)

Multiply this vec with a scalar.

Vec& operator/=(double s)

Divide this Vec with a scalar.

double operator[](int n) const

const indexing

double& operator[](int n)

Non-const indexing.