# cee::Vec3d

class Vec3d

Vector class for a 3D double vector.

Public Functions

Vec3d()

Constructs a null vector.

Vec3d(const Vec3d &other)

Constructs a vector as a copy of other.

Vec3d(double x, double y, double z)

Constructs a vector from an x, y and z coordinate.

Vec3d &operator=(const Vec3d &other)

Assigns other to this vector and returns a reference to this vector.

bool operator==(const Vec3d &rhs) const

Returns true if two vectors are equal, otherwise returns false.

An exact match is required x() == rhs.x(), etc.

bool operator!=(const Vec3d &rhs) const

Returns true if two vectors are not equal, otherwise returns false.

Exact comparison is used (!= between doubles)

const Vec3d operator+(const Vec3d &rhs) const

Returns a vector that is this vector added with rhs.

const Vec3d operator-(const Vec3d &rhs) const

Returns a vector that is this vector subtracted with rhs.

const Vec3d operator*(double scalar) const

Returns a vector that is this vector multiplied by a given scalar.

const Vec3d operator/(double scalar) const

Returns a vector that is this vector divided by a given scalar.

Vec3d &operator+=(const Vec3d &rhs)

Adds the given rhs vector to this.

Vec3d &operator-=(const Vec3d &rhs)

Subtracts the given rhs vector from this.

Vec3d &operator*=(double scalar)

Multiplies every component of this vector by the given scalar.

Vec3d &operator/=(double scalar)

Divides every component of this vector by the given scalar.

double operator*(const Vec3d &rhs) const

Computes the dot product of this and rhs and return the result (scalar)

Formula:

```S = tx*rx + ty*ry + tz*rz
```

const Vec3d operator^(const Vec3d &rhs) const

Computes the cross product of this and rhs and return the result (vector)

Formula:

```vec = <ty*rz - tz*ry, tz*rx - tx*rz, tx*ry - ty*rx>
```

const double &x() const

X element of the vector.

const double &y() const

Y element of the vector.

const double &z() const

Z element of the vector.

double &x()

X element of the vector.

double &y()

Y element of the vector.

double &z()

Z element of the vector.

void set(double x, double y, double z)

Sets x, y and z value.

void transformPoint(const Mat4d &m)

Transforms this point with the transformation matrix m.

void transformVector(const Mat4d &m)

Transforms this vector with the transformation matrix m.

bool normalize()

Normalizes this vector.

Returns false if the vector is a null vector. Otherwise returns true.

double length() const

Returns the length of this vector.

double lengthSquared() const

Returns the length of this vector.

double angle(const Vec3d &other)

Returns the angle (in radians) between this vector and the other.

Public Static Functions

static double dot(const Vec3d &v1, const Vec3d &v2)

Returns the dot product of v1 and v2.

Formula:

```S = tx*rx + ty*ry + tz*rz
```

static Vec3d cross(const Vec3d &v1, const Vec3d &v2)

Returns the cross-product of vectors v1 and v2, which corresponds to the normal vector of a plane defined by v1 and v2.

Friends

inline friend Vec3d operator*(double scalar, const Vec3d &v)

Returns a vector that is the vector v multiplied by a given scalar.