FlowField3D

class FlowField3D @JvmOverloads constructor(val graph: VoxelGraph, val sources: Set<Voxel>, val cellSize: Double = Defaults.cellSize, val origin: Point3D = Defaults.origin)(source)

A precomputed distance-from-sources field over a VoxelGraph, exposed at point-level granularity for continuous-space 3D agents (drones, UAVs, AUVs). The 3D analog of FlowField.

Wraps three things that previously had to be carried in parallel: the graph, a set of goal voxels (sources), and the distanceField map. Adds point-level conversions (voxelOf / centerOf) so drones holding continuous 3D positions can query the field directly.

Construction runs one multi-source Dijkstra. Queries are O(1) for distanceAt / arrivedAt and O(|passable neighbors|) — up to 26 with Moore-26 — for directionAt. Reconstruct (with the same or different sources) to refresh; reconstruction is cheap, so building a fresh FlowField3D in initialize() of each replication is the standard pattern.

Typical use (drones routing to nearest charging volume):

class DroneDelivery(parent: ModelElement) : AgentModel(parent, "delivery") {
val graph: VoxelGraph = ...
val chargers: Set<Voxel> = setOf(Voxel(0, 0, 0), Voxel(10, 0, 0))
lateinit var field: FlowField3D
override fun initialize() {
super.initialize()
field = FlowField3D(graph, chargers)
}
}
// Per-drone: while (!field.arrivedAt(myPos)) {
// step in field.directionAt(myPos) * speed
// }

Geometry model: voxels form a uniform 3D grid of side cellSize anchored at origin. Voxel (c, r, l) covers the half-open box [origin.x + c*cellSize, origin.x + (c+1)*cellSize) and similarly on y and z, with center at centerOf(Voxel(c, r, l)). For non- uniform or transformed layouts, subclass or compose; the simple uniform case covers every shipped example.

Parameters

graph

the underlying 3D lattice

sources

voxels treated as goals (distance = 0). Must not be empty.

cellSize

side length of each voxel in continuous space. Must be positive.

origin

continuous-space anchor of voxel (0, 0, 0)'s lower-left-bottom corner.

Constructors

Link copied to clipboard
constructor(graph: VoxelGraph, sources: Set<Voxel>, cellSize: Double = Defaults.cellSize, origin: Point3D = Defaults.origin)

Types

Link copied to clipboard
object Defaults

Mutable global defaults for FlowField3D construction. Mirrors FlowField.Defaults.

Properties

Link copied to clipboard
Link copied to clipboard

Distance-to-nearest-source for every reachable voxel. Unreachable voxels are absent. Source voxels map to 0.0.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

True if point's voxel is a source voxel — i.e., the agent at point has reached its goal. Out-of-bounds points are not arrived.

Link copied to clipboard
fun centerOf(voxel: Voxel): Point3D

Center coordinates of voxel in continuous space.

Link copied to clipboard

Unit vector pointing from point toward the center of the passable neighbor of point's voxel with the smallest field value (i.e., the most-downhill step in the 3D gradient).

Link copied to clipboard

Distance from point's voxel to the nearest source. Returns Double.POSITIVE_INFINITY for points whose voxel is out of bounds, blocked, or unreachable from any source.

Link copied to clipboard
fun voxelOf(point: Point3D): Voxel

Convert a 3D point in continuous space to the voxel containing it.