| TGX 1.0.8 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Classes | Typedefs | Functions
Vec3.h File Reference

3D vector. More...

`#include <stdint.h>`
`#include "Misc.h"`
`#include "Vec2.h"`

Go to the source code of this file.

## Classes
struct | tgx::Vec3< T >
| Generic 3D vector [specializations iVec3, fVec3, dVec3]. More...

## Typedefs
typedef Vec3< int > | tgx::iVec3
| Integer-valued 3D vector.
typedef Vec3< float > | tgx::fVec3
| Floating point valued 3D vector with single (float) precision.
typedef Vec3< double > | tgx::dVec3
| Floating point valued 3D vector with double precision.

## Functions
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Vec3< T > | tgx::normalize (Vec3< T > V)
| Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Vec3< T > | tgx::normalize_fast (Vec3< T > V)
| Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
template<typename T >
T | tgx::dist2 (const Vec3< T > V1, const Vec3< T > V2)
| Compute the squared euclidian distance between two vectors.
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | tgx::dist (Vec3< T > V1, const Vec3< T > V2)
| Compute the euclidian distance between two vectors. More...
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | tgx::dist_fast (Vec3< T > V1, const Vec3< T > V2)
| Compute the euclidian distance between two vectors. More...
template<typename T >
Vec3< T > | tgx::operator+ (Vec3< T > V1, const Vec3< T > V2)
| Addition operator. More...
template<typename T >
Vec3< T > | tgx::operator- (Vec3< T > V1, const Vec3< T > V2)
| Substraction operator. More...
template<typename T >
Vec3< T > | tgx::operator* (Vec3< T > V1, const Vec3< T > V2)
| Multiplication operator. More...
template<typename T >
Vec3< T > | tgx::operator/ (Vec3< T > V1, const Vec3< T > V2)
| Division operator. More...
template<typename T >
Vec3< T > | tgx::operator+ (const T a, Vec3< T > V)
| Scalar addition operator.
template<typename T >
Vec3< T > | tgx::operator+ (Vec3< T > V, const T a)
| Scalar addition operator.
template<typename T >
Vec3< T > | tgx::operator- (Vec3< T > V, const T a)
| Scalar substraction operator. More...
template<typename T >
Vec3< T > | tgx::operator* (const T a, Vec3< T > V)
| Scalar multiplication operator.
template<typename T >
Vec3< T > | tgx::operator* (Vec3< T > V, const T a)
| Scalar multiplication operator.
template<typename T >
Vec3< T > | tgx::operator/ (Vec3< T > V, const T a)
| Scalar division operator. More...
template<typename T >
T | tgx::dotProduct (const Vec3< T > U, const Vec3< T > V)
| Return the dot product U.V between two vectors.
template<typename T >
Vec3< T > | tgx::crossProduct (const Vec3< T > &U, const Vec3< T > &V)
| Return the cross product of U x V.
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Vec3< T > | tgx::lerp (Tfloat alpha, Vec3< T > V1, Vec3< T > V2)
| Linear interpolation: V1 + alpha(V2 - V1).

## Detailed Description

3D vector.

## Function Documentation

## ◆ normalize()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>

Vec3< T > tgx::normalize | ( | Vec3< T > | V | ) |
| inline

Return the vector normalized to have unit norm (do nothing if the vector is 0).

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

## ◆ normalize_fast()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>

Vec3< T > tgx::normalize_fast | ( | Vec3< T > | V | ) |
| inline

Return the vector normalized to have unit norm (do nothing if the vector is 0).

Use fast_invsqrt() approximation to speedup computations.

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

## ◆ dist()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>

Tfloat tgx::dist | ( | Vec3< T > | V1,
|  | const Vec3< T > | V2
| ) |  |

Compute the euclidian distance between two vectors.

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

## ◆ dist_fast()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>

Tfloat tgx::dist_fast | ( | Vec3< T > | V1,
|  | const Vec3< T > | V2
| ) |  |

Compute the euclidian distance between two vectors.

Use fast_sqrt() approximation to speedup computations.

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

## ◆ operator+()

template<typename T >

Vec3< T > tgx::operator+ | ( | Vec3< T > | V1,
|  | const Vec3< T > | V2
| ) |  |
| inline

Addition operator.

Coordinates by coordinates

## ◆ operator-() [1/2]

template<typename T >

Vec3< T > tgx::operator- | ( | Vec3< T > | V1,
|  | const Vec3< T > | V2
| ) |  |
| inline

Substraction operator.

Coordinates by coordinates

## ◆ operator*()

template<typename T >

Vec3< T > tgx::operator* | ( | Vec3< T > | V1,
|  | const Vec3< T > | V2
| ) |  |
| inline

Multiplication operator.

Coordinates by coordinates

## ◆ operator/() [1/2]

template<typename T >

Vec3< T > tgx::operator/ | ( | Vec3< T > | V1,
|  | const Vec3< T > | V2
| ) |  |
| inline

Division operator.

Coordinates by coordinates

## ◆ operator-() [2/2]

template<typename T >

Vec3< T > tgx::operator- | ( | Vec3< T > | V,
|  | const T | a
| ) |  |
| inline

Scalar substraction operator.

Scalar substraction operator

## ◆ operator/() [2/2]

template<typename T >

Vec3< T > tgx::operator/ | ( | Vec3< T > | V,
|  | const T | a
| ) |  |
| inline

Scalar division operator.

Scalar division operator