Bardo.Examples.Applications.Flatland.FlatlandUtils (Bardo v0.1.0)
View SourceUtility functions for the Flatland simulation.
This module provides utility functions for creating and managing the Flatland environment, including world creation, agent placement, and ray-object intersections for sensor calculations.
Summary
Functions
Creates a new Flatland world with the specified dimensions.
Normalizes a vector to a unit vector.
Maps object type to color value.
Places a specified number of predators and prey randomly in the world.
Places a specified number of plants randomly in the world.
Calculates the shortest intersection line between a ray and a circular object.
Calculates the intersection of a ray with the boundary of a rectangular world.
Functions
Creates a new Flatland world with the specified dimensions.
Parameters
width
- The width of the worldheight
- The height of the world
Returns
- A map representing the Flatland world with plants, predators, and prey
Normalizes a vector to a unit vector.
Maps object type to color value.
Returns:
- -0.5 for plants (green)
- 0.0 for prey (blue)
- 0.5 for predators (red)
Places a specified number of predators and prey randomly in the world.
Parameters
world
- The world mappredator_count
- The number of predators to placeprey_count
- The number of prey to place
Returns
- The updated world map with predators and prey
Places a specified number of plants randomly in the world.
Parameters
world
- The world mapplant_count
- The number of plants to place
Returns
- The updated world map with plants
@spec shortest_intr_line( {float(), float()}, {float(), float()}, {float(), float(), float()} ) :: float() | :no_intersection
Calculates the shortest intersection line between a ray and a circular object.
Parameters:
- ray_origin: {x, y} coordinates of ray origin
- ray_dir: {dx, dy} ray direction vector
- object: {x, y, r} object position and radius
Returns:
- :no_intersection if there is no intersection
- distance to the intersection point
This function is a direct port of the Erlang implementation, which uses vector math to calculate ray-circle intersections.
@spec world_boundary_intersection( {float(), float()}, {float(), float()}, float(), float() ) :: {float(), float(), float()} | :no_intersection
Calculates the intersection of a ray with the boundary of a rectangular world.
This is useful for determining how far a ray can travel before hitting a wall, which is important for sensors that need to detect world boundaries.