taps.apps.physics¶
TerrainConfig
dataclass
¶
TerrainConfig(
width: int,
height: float,
resolution: int,
scale: float,
octaves: int,
persistence: float,
lacunarity: float,
filter_size: int,
)
Terrain configuration.
SimulationConfig
dataclass
¶
SimulationConfig(
ball_diameter: float,
ball_mass: float,
tick_rate: int,
total_time: int,
real_time: bool,
)
Simulation configuration.
PhysicsApp
¶
PhysicsApp(
num_simulations: int,
terrain: TerrainConfig,
simulation: SimulationConfig,
seed: int | None = None,
)
Physics simulation application.
Simulate the physics of golf balls landing and rolling on a golf green.
Parameters:
-
num_simulations
(int
) –Number of balls to simulate.
-
terrain
(TerrainConfig
) –Terrain configuration.
-
simulation
(SimulationConfig
) –Simulation configuration.
-
seed
(int | None
, default:None
) –Random seed.
Source code in taps/apps/physics.py
close
¶
run
¶
Run the application.
Parameters:
Source code in taps/apps/physics.py
create_contour_plot
¶
create_contour_plot(
initial_positions: list[Position],
final_positions: list[Position],
heightmap: NDArray[float64],
config: TerrainConfig,
filepath: str | Path,
) -> None
Write contour plot with initial/final ball positions.
Parameters:
-
initial_positions
(list[Position]
) –Initial ball positions.
-
final_positions
(list[Position]
) –Final ball positions.
-
heightmap
(NDArray[float64]
) –Terrain heightmap.
-
config
(TerrainConfig
) –Terrain configuration.
-
filepath
(str | Path
) –Output file.
Source code in taps/apps/physics.py
create_terrain_plot
¶
create_terrain_plot(
initial_positions: list[Position],
final_positions: list[Position],
heightmap: NDArray[float64],
config: TerrainConfig,
filepath: str | Path,
) -> None
Write 3D terrain mesh with heatmap of final ball positions.
Parameters:
-
initial_positions
(list[Position]
) –Initial ball positions.
-
final_positions
(list[Position]
) –Final ball positions.
-
heightmap
(NDArray[float64]
) –Terrain heightmap.
-
config
(TerrainConfig
) –Terrain configuration.
-
filepath
(str | Path
) –Output file.
Source code in taps/apps/physics.py
generate_initial_positions
¶
generate_initial_positions(
num_balls: int,
config: TerrainConfig,
seed: int | None = None,
) -> list[Position]
Generate initial ball positions.
Parameters:
-
num_balls
(int
) –Number of balls.
-
config
(TerrainConfig
) –Terrain config used to bound locations of balls.
-
seed
(int | None
, default:None
) –Random seed for initial positions.
Returns:
-
list[Position]
–List of ball positions.
Source code in taps/apps/physics.py
generate_noisemap
¶
generate_noisemap(
config: TerrainConfig, seed: int | None = None
) -> NDArray[float64]
Generate Perlin noise map for terrain generation.
Parameters:
-
config
(TerrainConfig
) –Terrain configuration.
-
seed
(int | None
, default:None
) –Random seed.
Returns:
Source code in taps/apps/physics.py
generate_vertices
¶
generate_vertices(
heightmap: NDArray[float64], config: TerrainConfig
) -> Terrain
Generate vertex mesh from heighmap.
Parameters:
-
heightmap
(NDArray[float64]
) –Terrain heighmap.
-
config
(TerrainConfig
) –Terrain config.
Returns:
-
Terrain
–Vertex mesh.
Source code in taps/apps/physics.py
simulate
¶
simulate(
terrain: Terrain,
positions: list[Position],
sim_config: SimulationConfig,
terrain_config: TerrainConfig,
) -> list[Position]
Simulate balls landing on terrain.
Parameters:
-
terrain
(Terrain
) –Terrain.
-
positions
(list[Position]
) –Initial ball positions.
-
sim_config
(SimulationConfig
) –Simulation configuration.
-
terrain_config
(TerrainConfig
) –Terrain configuration.
Returns:
-
list[Position]
–List of final ball positions.