sim #
Constants #
const (
default_rope_length = 0.25
default_bearing_mass = 0.03
default_magnet_spacing = 0.05
default_magnet_height = 0.03
default_magnet_strength = 10.0
default_gravity = 4.9
)
const (
default_width = 600
default_height = 600
)
fn compute_result #
fn compute_result(request SimRequest) &SimResult
fn log #
fn log(info string)
log is a helper function to print debug info
fn new_grid_settings #
fn new_grid_settings(settings GridSettings) GridSettings
fn new_state #
fn new_state(state SimState) SimState
fn run #
fn run(params SimParams, settings RunnerSettings)
fn sim_params #
fn sim_params(params SimParams) SimParams
fn sim_worker #
fn sim_worker(id int, request_chan chan &SimRequest, result_channels []chan &SimResult)
fn vector #
fn vector(data Vector3D) Vector3D
vector creates a Vector3D passing x,y,z as parameteres
type SimFinishHandler #
type SimFinishHandler = fn () ?
type SimRequestHandler #
type SimRequestHandler = fn (request &SimRequest) ?
type SimStartHandler #
type SimStartHandler = fn () ?
struct GridSettings #
struct GridSettings {
pub:
width int = sim.default_width
height int = sim.default_height
}
struct RunnerSettings #
struct RunnerSettings {
pub:
grid GridSettings
on_request SimRequestHandler
on_start SimStartHandler
on_finish SimFinishHandler
}
struct SimParams #
struct SimParams {
rope_length f64 = sim.default_rope_length
bearing_mass f64 = sim.default_bearing_mass
magnet_spacing f64 = sim.default_magnet_spacing
magnet_height f64 = sim.default_magnet_height
magnet_strength f64 = sim.default_magnet_strength
gravity f64 = sim.default_gravity
}
fn (SimParams) get_rope_vector #
fn (params SimParams) get_rope_vector(state SimState) Vector3D
fn (SimParams) get_forces_sum #
fn (params SimParams) get_forces_sum(state SimState) Vector3D
fn (SimParams) get_grav_force #
fn (params SimParams) get_grav_force(state SimState) Vector3D
fn (SimParams) get_magnet_position #
fn (params SimParams) get_magnet_position(theta f64) Vector3D
fn (SimParams) get_magnet_force #
fn (params SimParams) get_magnet_force(theta f64, state SimState) Vector3D
fn (SimParams) get_magnet_dist #
fn (params SimParams) get_magnet_dist(theta f64, state SimState) f64
fn (SimParams) get_magnet1_force #
fn (params SimParams) get_magnet1_force(state SimState) Vector3D
fn (SimParams) get_magnet2_force #
fn (params SimParams) get_magnet2_force(state SimState) Vector3D
fn (SimParams) get_magnet3_force #
fn (params SimParams) get_magnet3_force(state SimState) Vector3D
fn (SimParams) get_tension_force #
fn (params SimParams) get_tension_force(state SimState, f_passive Vector3D) Vector3D
struct SimRequest #
struct SimRequest {
params SimParams
state SimState
pub:
id int
}
struct SimResult #
struct SimResult {
state SimState
pub:
id int
magnet1_distance f64
magnet2_distance f64
magnet3_distance f64
}
struct SimState #
struct SimState {
mut:
position Vector3D
velocity Vector3D
accel Vector3D
}
fn (SimState) satisfy_rope_constraint #
fn (mut state SimState) satisfy_rope_constraint(params SimParams)
fn (SimState) increment #
fn (mut state SimState) increment(delta_t f64, params SimParams)
fn (SimState) done #
fn (state SimState) done() bool
struct Vector3D #
struct Vector3D {
x f64
y f64
z f64
}
Vector3D is a 3D vector
fn (Vector3D) + #
fn (v Vector3D) + (v2 Vector3D) Vector3D
addition
fn (Vector3D) * #
fn (v Vector3D) * (v2 Vector3D) f64
dot product
fn (Vector3D) scale #
fn (v Vector3D) scale(scalar f64) Vector3D
scale gets a scaled vector
fn (Vector3D) norm_squared #
fn (v Vector3D) norm_squared() f64
norm_squared returns the square of the norm of the vector
fn (Vector3D) norm #
fn (v Vector3D) norm() f64
norm returns the norm of the vector
- Constants
- fn compute_result
- fn log
- fn new_grid_settings
- fn new_state
- fn run
- fn sim_params
- fn sim_worker
- fn vector
- type SimFinishHandler
- type SimRequestHandler
- type SimStartHandler
- struct GridSettings
- struct RunnerSettings
- struct SimParams
- struct SimRequest
- struct SimResult
- struct SimState
- struct Vector3D