# shz::vec3

Source: https://sh4zam.com/api/cpp/vec3/

3D Vector type

C++ structure for representing a 3-dimensional vector.

- **Header:** `#include <sh4zam/shz_vector.hpp>` ([source](https://github.com/gyrovorbis/sh4zam/blob/ba1e30c88d49df0311870b229e1dd860ef26c477/include/sh4zam/shz_vector.hpp#L475))
- **C type:** [`shz_vec3_t`](https://sh4zam.com/api/vector/shz_vec3_t/) (layout-compatible; the C API accepts it directly)
- **Bases:** `shz::vecN< vec3, shz_vec3_t, 3 >`

## Static functions

### orthonormalize

```cpp
static auto orthonormalize(const vec3 &in1, const vec3 &in2) noexcept
static void orthonormalize(const vec3 &in1, const vec3 &in2, vec3 *out1, vec3 *out2) noexcept
```

Returns 2 3D vectors which are normalized and orthogonal to the two input vectors as a std::pair\<>.

Calls: [`shz_vec3_orthonormalize()`](https://sh4zam.com/api/vector/shz_vec3_orthonormalize/)

### cubic_hermite

```cpp
static vec3 cubic_hermite(const vec3 &v1, const vec3 &tangent1, const vec3 &v2, const vec3 &tangent2, float amount) noexcept
```

Calculates the cubic hermite interpolation between two vectors and their tangents.

Calls: [`shz_vec3_cubic_hermite()`](https://sh4zam.com/api/vector/shz_vec3_cubic_hermite/)

### from_angles

```cpp
static vec3 from_angles(float azimuth_rads, float elevation_rads) noexcept
```

Returns a 3D vector which forms the given angles with the +X axis, in radians.

Calls: [`shz_vec3_from_angles()`](https://sh4zam.com/api/vector/shz_vec3_from_angles/)

### from_angles_deg

```cpp
static vec3 from_angles_deg(float azimuth_deg, float elevation_deg) noexcept
```

Returns a 3D vector which forms the given angles with the +X axis, in degrees.

Calls: [`shz_vec3_from_angles_deg()`](https://sh4zam.com/api/vector/shz_vec3_from_angles_deg/)

### from

```cpp
static CppType shz::vecN< CRTP, C, R >::from(const auto &raw) noexcept
```

Conversion operator for going from a layout-compatible vector type to a SH4ZAM vector type.

Inherited from `shz::vecN`.

### lerp

```cpp
static CppType shz::vecN< CRTP, C, R >::lerp(const CppType &start, const CppType &end, float t) noexcept
```

Returns the vector that is linearly interpolated between the two given vectors by the `0.0f-1.0f` factor, `t`.

Calls: [`shz_vec3_lerp()`](https://sh4zam.com/api/vector/shz_vec3_lerp/) (inherited from `shz::vecN`)

### smoothstep

```cpp
static CppType shz::vecN< CRTP, C, R >::smoothstep(const CppType &vec, T &&edge0, T &&edge1) noexcept
```

Returns a vector where each component is smoothly interpolated from 0 to 1 between edge0 and edge1.

Calls: [`shz_vec3_smoothstep()`](https://sh4zam.com/api/vector/shz_vec3_smoothstep/) (inherited from `shz::vecN`)

### smoothstep_safe

```cpp
static CppType shz::vecN< CRTP, C, R >::smoothstep_safe(const CppType &vec, T &&edge0, T &&edge1) noexcept
```

Returns a vector where each component is smoothly interpolated from 0 to 1 between edge0 and edge1.

Calls: [`shz_vec3_smoothstep_safe()`](https://sh4zam.com/api/vector/shz_vec3_smoothstep_safe/) (inherited from `shz::vecN`)

### step

```cpp
static CppType shz::vecN< CRTP, C, R >::step(const CppType &vec, T &&edge) noexcept
```

Compares each component of the vector to the edge. 0 returned in that component if x\[i\] \< edge. Otherwise the component is 1.

Calls: [`shz_vec3_step()`](https://sh4zam.com/api/vector/shz_vec3_step/) (inherited from `shz::vecN`)

## Members

### rotate_x

```cpp
vec3 rotate_x(float angle) const noexcept
```

Rotates a 3D vector about the X axis by the given number of radians.

Calls: [`shz_vec3_rotate_x()`](https://sh4zam.com/api/vector/shz_vec3_rotate_x/)

### rotate_y

```cpp
vec3 rotate_y(float angle) const noexcept
```

Rotates a 3D vector about the Y axis by the given number of radians.

Calls: [`shz_vec3_rotate_y()`](https://sh4zam.com/api/vector/shz_vec3_rotate_y/)

### rotate_z

```cpp
vec3 rotate_z(float angle) const noexcept
```

Rotates a 3D vector about the Z axis by the given number of radians.

Calls: [`shz_vec3_rotate_z()`](https://sh4zam.com/api/vector/shz_vec3_rotate_z/)

### vec3

```cpp
vec3()=default
vec3(const shz_vec3_t &other) noexcept
vec3(float v) noexcept
vec3(float x, float y, float z) noexcept
vec3(const shz::vec2 &xy, float z) noexcept
vec3(float x, const shz::vec2 &yz) noexcept
vec3(const sincos &azimuth, const sincos &elevation) noexcept
```

Default constructor: does nothing.

### xy

```cpp
vec2 xy() const noexcept
```

### cross

```cpp
vec3 cross(const vec3 &other) const noexcept
```

Returns a 3D vector which forms the given angles with the +X axis.

Calls: [`shz_vec3_cross()`](https://sh4zam.com/api/vector/shz_vec3_cross/)

### triple

```cpp
float triple(const vec3 &b, const vec3 &c) const noexcept
```

Returns the 3D vector "triple product" between the given vector and vectors `a` and `b`.

Calls: [`shz_vec3_triple()`](https://sh4zam.com/api/vector/shz_vec3_triple/)

### perp

```cpp
vec3 perp() const noexcept
```

Returns a 3D vector which is perpendicular to this vector.

Calls: [`shz_vec3_perp()`](https://sh4zam.com/api/vector/shz_vec3_perp/)

### reject

```cpp
vec3 reject(const vec3 &onto) const noexcept
```

Returns the 3D reject vector of the given vector and another.

Calls: [`shz_vec3_reject()`](https://sh4zam.com/api/vector/shz_vec3_reject/)

### barycenter

```cpp
vec3 barycenter(const vec3 &a, const vec3 &b, const vec3 &c) const noexcept
```

Computes the barycentric coordinates `<u, v, w>` for the given 3D vector, within the plane of the triangle formed by the given vertices, `a`, `b`, and `c`.

Calls: [`shz_vec3_barycenter()`](https://sh4zam.com/api/vector/shz_vec3_barycenter/)

### vecN

```cpp
shz::vecN< CRTP, C, R >::vecN() noexcept=default
shz::vecN< CRTP, C, R >::vecN(const vecN &other) noexcept=default
shz::vecN< CRTP, C, R >::vecN(const CType &other) noexcept
shz::vecN< CRTP, C, R >::vecN(const volatile CType &other) noexcept
```

Default constructor, does nothing.

### dot

```cpp
float shz::vecN< CRTP, C, R >::dot(const CppType &other) const noexcept
vec2 shz::vecN< CRTP, C, R >::dot(const CppType &v1, const CppType &v2) const noexcept
vec3 shz::vecN< CRTP, C, R >::dot(const CppType &v1, const CppType &v2, const CppType &v3) const noexcept
```

Returns the dot product of the given vector and another.

### abs

```cpp
CppType shz::vecN< CRTP, C, R >::abs() const noexcept
```

Returns a new vector whose components are the absolute value of the given vector.

Calls: [`shz_vec3_abs()`](https://sh4zam.com/api/vector/shz_vec3_abs/) (inherited from `shz::vecN`)

### angle_between

```cpp
float shz::vecN< CRTP, C, R >::angle_between(const CppType &other) const noexcept
```

Returns the angle between the given vector and another, in radians.

Calls: [`shz_vec3_angle_between()`](https://sh4zam.com/api/vector/shz_vec3_angle_between/) (inherited from `shz::vecN`)

### angles

```cpp
auto shz::vecN< CRTP, C, R >::angles() const noexcept
```

Returns the angle(s) created between the given vector axis and the +X axis, in radians.

Calls: [`shz_vec3_angles()`](https://sh4zam.com/api/vector/shz_vec3_angles/) (inherited from `shz::vecN`)

### ceil

```cpp
CppType shz::vecN< CRTP, C, R >::ceil() const noexcept
```

Returns a new vector with the component-wise ceil of the given vector.

Calls: [`shz_vec3_ceil()`](https://sh4zam.com/api/vector/shz_vec3_ceil/) (inherited from `shz::vecN`)

### clamp

```cpp
CppType shz::vecN< CRTP, C, R >::clamp(float min, float max) const noexcept
```

Returns a new vector whose values are the clamped components of the given vector.

Calls: [`shz_vec3_clamp()`](https://sh4zam.com/api/vector/shz_vec3_clamp/) (inherited from `shz::vecN`)

### deref

```cpp
CppType & shz::vecN< CRTP, C, R >::deref(const auto *raw) noexcept
```

Conversion operator for accessing an existing pointer type as though it were a refrence to a SH4ZAM type.

Inherited from `shz::vecN`.

### direction

```cpp
CppType shz::vecN< CRTP, C, R >::direction() const noexcept
```

Returns the direction vector resulting from normalizing the given vector.

Calls: [`shz_vec3_normalize()`](https://sh4zam.com/api/vector/shz_vec3_normalize/) (inherited from `shz::vecN`)

### direction_safe

```cpp
CppType shz::vecN< CRTP, C, R >::direction_safe() const noexcept
```

Returns the direction vector of a given vector, safely protecting against division-by-zero.

Calls: [`shz_vec3_normalize_safe()`](https://sh4zam.com/api/vector/shz_vec3_normalize_safe/) (inherited from `shz::vecN`)

### distance

```cpp
float shz::vecN< CRTP, C, R >::distance(const CppType &other) const noexcept
```

Returns the magnitude of the difference between two vectors as their distance.

Calls: [`shz_vec3_distance()`](https://sh4zam.com/api/vector/shz_vec3_distance/) (inherited from `shz::vecN`)

### distance_sqr

```cpp
float shz::vecN< CRTP, C, R >::distance_sqr(const CppType &other) const noexcept
```

Returns the value of the distance between two vectors squared (faster than actual distance).

Calls: [`shz_vec3_distance_sqr()`](https://sh4zam.com/api/vector/shz_vec3_distance_sqr/) (inherited from `shz::vecN`)

### floor

```cpp
CppType shz::vecN< CRTP, C, R >::floor() const noexcept
```

Returns a new vector with the component-wise floor of the given vector.

Calls: [`shz_vec3_floor()`](https://sh4zam.com/api/vector/shz_vec3_floor/) (inherited from `shz::vecN`)

### fract

```cpp
CppType shz::vecN< CRTP, C, R >::fract() const noexcept
```

Returns a new vector with the fractional part of each component.

Calls: [`shz_vec3_fract()`](https://sh4zam.com/api/vector/shz_vec3_fract/) (inherited from `shz::vecN`)

### inv

```cpp
CppType shz::vecN< CRTP, C, R >::inv() const noexcept
```

Returns a new vector whose components are the reciprocal values of the given vector.

Calls: [`shz_vec3_inv()`](https://sh4zam.com/api/vector/shz_vec3_inv/) (inherited from `shz::vecN`)

### inv_sqrtf

```cpp
CppType shz::vecN< CRTP, C, R >::inv_sqrtf() const noexcept
```

Returns a new vector whose components are the inverse square root of the given vector.

Calls: [`shz_vec3_inv_sqrtf()`](https://sh4zam.com/api/vector/shz_vec3_inv_sqrtf/) (inherited from `shz::vecN`)

### magnitude

```cpp
float shz::vecN< CRTP, C, R >::magnitude() const noexcept
```

Returns the magnitude of the given vector.

Calls: [`shz_vec3_magnitude()`](https://sh4zam.com/api/vector/shz_vec3_magnitude/) (inherited from `shz::vecN`)

### magnitude_inv

```cpp
float shz::vecN< CRTP, C, R >::magnitude_inv() const noexcept
```

Returns the inverse magnitude of the given vector.

Calls: [`shz_vec3_magnitude_inv()`](https://sh4zam.com/api/vector/shz_vec3_magnitude_inv/) (inherited from `shz::vecN`)

### magnitude_sqr

```cpp
float shz::vecN< CRTP, C, R >::magnitude_sqr() const noexcept
```

Returns the squared magnitude of the given vector.

Calls: [`shz_vec3_magnitude_sqr()`](https://sh4zam.com/api/vector/shz_vec3_magnitude_sqr/) (inherited from `shz::vecN`)

### max

```cpp
float shz::vecN< CRTP, C, R >::max() const noexcept
```

Returns the maximum value of every element within the vector.

Calls: [`shz_vec3_max()`](https://sh4zam.com/api/vector/shz_vec3_max/) (inherited from `shz::vecN`)

### maxv

```cpp
CppType shz::vecN< CRTP, C, R >::maxv(const CppType &other) const noexcept
```

Returns a new vector with the component-wise maximum of two vectors.

Calls: [`shz_vec3_maxv()`](https://sh4zam.com/api/vector/shz_vec3_maxv/) (inherited from `shz::vecN`)

### min

```cpp
float shz::vecN< CRTP, C, R >::min() const noexcept
```

Returns the minimum value of every element within the vector.

Calls: [`shz_vec3_min()`](https://sh4zam.com/api/vector/shz_vec3_min/) (inherited from `shz::vecN`)

### minv

```cpp
CppType shz::vecN< CRTP, C, R >::minv(const CppType &other) const noexcept
```

Returns a new vector with the component-wise minimum of two vectors.

Calls: [`shz_vec3_minv()`](https://sh4zam.com/api/vector/shz_vec3_minv/) (inherited from `shz::vecN`)

### move

```cpp
CppType shz::vecN< CRTP, C, R >::move(const CppType &target, float maxdist) const noexcept
```

Moves the given vector towards the target by the given `maxdist`.

Calls: [`shz_vec3_move()`](https://sh4zam.com/api/vector/shz_vec3_move/) (inherited from `shz::vecN`)

### neg

```cpp
CppType shz::vecN< CRTP, C, R >::neg() const noexcept
```

Returns a new vector whose components are the negative values of the given vector.

Calls: [`shz_vec3_neg()`](https://sh4zam.com/api/vector/shz_vec3_neg/) (inherited from `shz::vecN`)

### normalize

```cpp
void shz::vecN< CRTP, C, R >::normalize() noexcept
```

Normalizes the given vector.

Calls: [`shz_vec3_normalize()`](https://sh4zam.com/api/vector/shz_vec3_normalize/) (inherited from `shz::vecN`)

### normalize_safe

```cpp
void shz::vecN< CRTP, C, R >::normalize_safe() noexcept
```

Normalizes the given vector, safely protecting against division-by-zero.

Calls: [`shz_vec3_normalize_safe()`](https://sh4zam.com/api/vector/shz_vec3_normalize_safe/) (inherited from `shz::vecN`)

### normalized

```cpp
CppType shz::vecN< CRTP, C, R >::normalized() const noexcept
```

Return the normalized vector.

Calls: [`shz_vec3_normalize()`](https://sh4zam.com/api/vector/shz_vec3_normalize/) (inherited from `shz::vecN`)

### normalized_safe

```cpp
CppType shz::vecN< CRTP, C, R >::normalized_safe() const noexcept
```

Return the normalized vector, safely protecting against division-by-zero.

Calls: [`shz_vec3_normalize_safe()`](https://sh4zam.com/api/vector/shz_vec3_normalize_safe/) (inherited from `shz::vecN`)

### operator*=

```cpp
CppType & shz::vecN< CRTP, C, R >::operator*=(const CppType &other) noexcept
```

Overloaded multiplication assignment operator, multiplies and accumulates a vector onto the left-hand vector.

Inherited from `shz::vecN`.

### operator+=

```cpp
CppType & shz::vecN< CRTP, C, R >::operator+=(const CppType &other) noexcept
```

Overloaded operator for adding and accumulating a vector onto another.

Inherited from `shz::vecN`.

### operator-=

```cpp
CppType & shz::vecN< CRTP, C, R >::operator-=(const CppType &other) noexcept
```

Overloaded subtraction assignment operator, subtracts a vector from the left-hand vector.

Inherited from `shz::vecN`.

### operator/=

```cpp
CppType & shz::vecN< CRTP, C, R >::operator/=(const CppType &other) noexcept
```

Overloaded division assignment operator, divides the left vector by the right, assigning the left to the result.

Inherited from `shz::vecN`.

### project

```cpp
CppType shz::vecN< CRTP, C, R >::project(const CppType &onto) const noexcept
```

Returns the vector created from projecting the given vector onto another.

Calls: [`shz_vec3_project()`](https://sh4zam.com/api/vector/shz_vec3_project/) (inherited from `shz::vecN`)

### project_safe

```cpp
CppType shz::vecN< CRTP, C, R >::project_safe(const CppType &onto) const noexcept
```

Returns the vector created from projecting the given vector onto another, safely protecting against division-by-zero.

Calls: [`shz_vec3_project_safe()`](https://sh4zam.com/api/vector/shz_vec3_project_safe/) (inherited from `shz::vecN`)

### reflect

```cpp
CppType shz::vecN< CRTP, C, R >::reflect(const CppType &normal) const noexcept
```

Returns the vector created from reflecting the given vector over the normal of a surface.

Calls: [`shz_vec3_reflect()`](https://sh4zam.com/api/vector/shz_vec3_reflect/) (inherited from `shz::vecN`)

### refract

```cpp
CppType shz::vecN< CRTP, C, R >::refract(const CppType &normal, float eta) const noexcept
```

Returns the vector create from refracting the given incidence vector over the normal of a surface, using the given refraction ratio index.

Calls: [`shz_vec3_refract()`](https://sh4zam.com/api/vector/shz_vec3_refract/) (inherited from `shz::vecN`)

### round

```cpp
CppType shz::vecN< CRTP, C, R >::round() const noexcept
```

Returns a new vector with the component-wise rounding of the given vector.

Calls: [`shz_vec3_round()`](https://sh4zam.com/api/vector/shz_vec3_round/) (inherited from `shz::vecN`)

### saturate

```cpp
CppType shz::vecN< CRTP, C, R >::saturate() const noexcept
```

Returns a new vector with each component clamped to \[0, 1\].

Calls: [`shz_vec3_saturate()`](https://sh4zam.com/api/vector/shz_vec3_saturate/) (inherited from `shz::vecN`)

### sign

```cpp
CppType shz::vecN< CRTP, C, R >::sign() const noexcept
```

Returns a new vector with the sign of each component (-1, 0, or 1).

Calls: [`shz_vec3_sign()`](https://sh4zam.com/api/vector/shz_vec3_sign/) (inherited from `shz::vecN`)

### sqrtf

```cpp
CppType shz::vecN< CRTP, C, R >::sqrtf() const noexcept
```

Returns a new vector whose components are the square root of the given vector.

Calls: [`shz_vec3_sqrtf()`](https://sh4zam.com/api/vector/shz_vec3_sqrtf/) (inherited from `shz::vecN`)

### swizzle

```cpp
CppType shz::vecN< CRTP, C, R >::swizzle() const noexcept
```

Swizzle oeprator which takes a compile-time list of indices as non-type template arguments for the index each element should use as its new value.

Calls: [`shz_vec3_swizzle()`](https://sh4zam.com/api/vector/shz_vec3_swizzle/) (inherited from `shz::vecN`)

### to

```cpp
T shz::vecN< CRTP, C, R >::to() const noexcept
```

Conversion operator for going from a SH4ZAM vector type to another layout-compatible type.

Inherited from `shz::vecN`.
