viva_math/vector

Vector operations for 3D space (PAD model).

Vec3 is the fundamental type for emotional state in VIVA:

Types

A 3-dimensional vector representing PAD emotional state.

pub type Vec3 {
  Vec3(x: Float, y: Float, z: Float)
}

Constructors

  • Vec3(x: Float, y: Float, z: Float)

Values

pub fn add(a: Vec3, b: Vec3) -> Vec3

Add two vectors.

pub fn arousal(v: Vec3) -> Float

Get Arousal component (y).

pub fn average(v: Vec3) -> Float

Average of all components.

pub fn clamp(v: Vec3, min: Float, max: Float) -> Vec3

Clamp each component to [min, max] range.

pub fn clamp_pad(v: Vec3) -> Vec3

Clamp vector to PAD range [-1, 1] for all components.

pub fn cross(a: Vec3, b: Vec3) -> Vec3

Cross product of two vectors.

pub fn distance(a: Vec3, b: Vec3) -> Float

Euclidean distance between two vectors.

pub fn distance_squared(a: Vec3, b: Vec3) -> Float

Squared distance between two vectors (avoids sqrt).

pub fn div(v: Vec3, s: Float) -> Result(Vec3, Nil)

Divide vector by scalar. Returns Error if scalar is zero.

pub fn dominance(v: Vec3) -> Float

Get Dominance component (z).

pub fn dot(a: Vec3, b: Vec3) -> Float

Dot product of two vectors.

pub fn from_list(values: List(Float)) -> Result(Vec3, Nil)

Create a Vec3 from a list of 3 floats. Returns Error if list doesn’t have exactly 3 elements.

pub fn is_close(a: Vec3, b: Vec3, tolerance: Float) -> Bool

Check if two vectors are approximately equal.

pub fn length(v: Vec3) -> Float

Length (magnitude) of a vector.

pub fn length_squared(v: Vec3) -> Float

Squared length of a vector (avoids sqrt for comparisons).

pub fn lerp(a: Vec3, b: Vec3, t: Float) -> Vec3

Linear interpolation between two vectors.

pub fn map(v: Vec3, f: fn(Float) -> Float) -> Vec3

Apply a function to each component.

pub fn max(a: Vec3, b: Vec3) -> Vec3

Component-wise maximum of two vectors.

pub fn min(a: Vec3, b: Vec3) -> Vec3

Component-wise minimum of two vectors.

pub fn multiply(a: Vec3, b: Vec3) -> Vec3

Component-wise multiplication (Hadamard product).

pub fn negate(v: Vec3) -> Vec3

Negate a vector.

pub fn normalize(v: Vec3) -> Vec3

Normalize a vector to unit length. Returns zero vector if input has zero length.

pub fn pad(
  pleasure: Float,
  arousal: Float,
  dominance: Float,
) -> Vec3

Create a PAD vector (Pleasure, Arousal, Dominance).

pub fn pleasure(v: Vec3) -> Float

Get Pleasure component (x).

pub fn scale(v: Vec3, s: Float) -> Vec3

Multiply vector by scalar.

pub fn splat(value: Float) -> Vec3

Create a vector with all components set to the same value.

pub fn sub(a: Vec3, b: Vec3) -> Vec3

Subtract vector b from vector a.

pub fn sum(v: Vec3) -> Float

Sum of all components.

pub fn to_list(v: Vec3) -> List(Float)

Convert Vec3 to a list of floats.

pub fn weighted_average(
  vectors: List(Vec3),
  weights: List(Float),
) -> Result(Vec3, Nil)

Compute weighted average of vectors. weights and vectors must have same length.

pub fn zero() -> Vec3

Create a zero vector.

Search Document