Raxol.Animation.Physics.ForceField (Raxol v0.5.0)
View SourceForce field implementation for physics simulations.
Force fields apply forces to physics objects within their influence. Types of force fields include:
- Point (radial forces emanating from a point)
- Directional (constant force in a direction, like wind)
- Vortex (spinning forces)
- Noise (random forces based on position)
- Custom (user-defined force function)
Summary
Functions
Calculates the force applied by a field on an object.
Creates a new custom force field.
Creates a new directional force field.
Creates a new noise force field.
Creates a new point force field.
Creates a new vortex force field.
Types
@type field_type() :: :point | :directional | :vortex | :noise | :custom
@type t() :: %Raxol.Animation.Physics.ForceField{ direction: Raxol.Animation.Physics.Vector.t(), falloff: :linear | :quadratic | :none, function: (any(), any() -> Raxol.Animation.Physics.Vector.t()) | nil, position: Raxol.Animation.Physics.Vector.t(), properties: map(), radius: float(), strength: float(), type: field_type() }
Functions
Calculates the force applied by a field on an object.
Creates a new custom force field.
A custom force field uses a user-provided function to calculate forces.
Options
:function
- Function to calculate force (fn object, field -> force_vector end):properties
- Additional properties for the function (default: %{})
Creates a new directional force field.
A directional force field applies a constant force in a specific direction, like wind or gravity.
Options
:direction
- Direction of the force (default: up):strength
- Strength of the field (default: 1.0)
Creates a new noise force field.
A noise force field applies pseudo-random forces based on position.
Options
:strength
- Strength of the field (default: 1.0):scale
- Scale of the noise (default: 0.1):seed
- Random seed (default: random)
Creates a new point force field.
A point force field applies forces radiating from or towards a point. Positive strength = repulsive, Negative strength = attractive.
Options
:position
- Position of the field (default: origin):strength
- Strength of the field (default: 1.0):radius
- Radius of influence (default: 10.0):falloff
- How force decreases with distance (:linear, :quadratic, :none) (default: :quadratic)
Creates a new vortex force field.
A vortex force field applies spinning forces around an axis.
Options
:position
- Center of the vortex (default: origin):direction
- Axis of rotation (default: up):strength
- Strength of the field (default: 1.0):radius
- Radius of influence (default: 10.0):falloff
- How force decreases with distance (:linear, :quadratic, :none) (default: :linear)