Vec3<T> class

<oceansdk/math/vec3.h>

Description

This class allows manipulating 3D vectors and passing them through the SDK Interface functions

Namespace

This class is in the root namespace

Public members

template<typename T>
class Vec3
Template Parameters

T – The underlying numeric type, should be float or double

Vec3()

Constructs a Vec3 with uninitialized values

Vec3(T x1, T x2, T x3)

Constructs a Vec3 and initialize it with provided coordinates

Vec3(const T *data)

Constructs a Vec3 and initialize it with coordinates data[0], data[1] and data[2]

T &operator[](int i)

Returns a reference to the ith coordinate. i should be 0, 1 or 2

T &at(int i)

Same as above

const T &operator[](int i) const

Returns a const reference to the ith coordinate. i should be 0, 1 or 2

const T &at(int i) const

Same as above

Vec3<T> operator+(const Vec3<T> &other) const

Returns the sum of this vector and other

Vec3<T> operator-(const Vec3<T> &other) const

Returns the difference of this vector and other

Vec3<T> operator*(T scalar) const

Returns the product of this vector and scalar

Vec3<T> operator*(const Vec3<T> &other) const

Returns the term by term product of this vector and other

Vec3<T> operator-() const

Returns the opposite of this (negates all coordinates)

Vec3<T> &operator+=(const Vec3<T> &other) const

Adds other to this vector and returns a reference to this vector

Vec3<T> &operator*=(T scalar) const

Multiplies this vector by scalar and returns a reference to this vector

bool operator!=(const Vec3<T> &other) const

Returns true if this and other have not all coordinates equal, false otherwise

bool operator==(const Vec3<T> &other) const

Returns true if this and other have all coordinates equal, false otherwise

bool isFinite() const

Returns true if this vector coordinates are all finite (not NaN or inf)

Vec3<T> operator^(const Vec3<T> &other) const

Returns the cross product of this vector and other

Vec3<T> crossProduct(const Vec3<T> &other) const

Returns the cross product of this vector and other

Vec3<T> arbitraryOrthoUnit() const

Returns a normalized vector orthogonal to this (arbitrary amongst all possible values)

T operator|(const Vec3<T> &other) const

Returns the dot product of this vector and other

T dotProduct(const Vec3<T> &other) const

Returns the dot product of this vector and other

Vec3<T> normalized() const

Returns the this normalized or a zero vector if this is zero

T squareLength() const

Returns the square length of this

T length() const

Returns the length of this

T azimuthY() const

Returns the azimuth of this in polar coordinates (poles on Y axis)

T elevationY() const

Returns the elevation of this in polar coordinates (poles on Y axis)

T azimuthZ() const

Returns the azimuth of this in polar coordinates (poles on Z axis)

T elevationZ() const

Returns the elevation of this in polar coordinates (poles on Z axis)

Vec3<T> clamped0() const

Returns a vector for which coordinates are those of this clamped to 0 if negative

Vec3<T> clamped01() const

Returns a vector for which coordinates are those of this clamped to the [0-1] interval

Vec3<T> zFlipped() const

Returns a vector equal to this but the z coordinate negated

Vec3<T> xyFlipped() const

Returns a vector equal to this but x and y coordinates negated

Vec3<T> zAbs() const

Returns a vector equal to this but the z coordinate replaced by its absolute value

const T *data() const

Returns a const pointer to the vector coordinates

T *data()

Returns a pointer to the vector coordinates

template<typename U>
Vec3<U> toVec3() const

Converts a Vec3<T> to a Vec3<U> by casting coordinates from T to U

std::string toString() const

Converts the vector to a string with space separated values

static Vec3<T> fromString(const std::string &str, bool *ok = 0)
Parameters
  • str – The string to convert to a vector

  • ok – If non null, the pointed value will be set to true if successful, false otherwise

Creates a vector from a string with space separated values

static Vec3<T> crossProduct(const Vec3<T> &v1, const Vec3<T> &v2)

Returns the cross product between v1 and v2

static Vec3<T> lerp(const Vec3<T> &v1, const Vec3<T> &v2, T t)
Parameters
  • v1 – First vector

  • v2 – Second vector

  • t – Weight between v1 and v2

Returns the linear combination betwwen two vectors v1 * (1 - t) + v2 * t

static Vec3<T> polarY(T azimuth, T elevation, T distance)

Returns a vector from polar coordinates (Y axis pole)

static Vec3<T> polarZ(T azimuth, T elevation, T distance)

Returns a vector from polar coordinates (Z axis pole)

static bool orthoNormalize(Vec3<T> *v1, Vec3<T> *v2, Vec3<T> *v3)

Orthonormalizes the basis *v1, *v2, *v3.

The direction of *v1 is conserved, and the plane (*v1,*v2) as well