pythagodzilla d8ed237d46
2026-03-19 19:41:47 +08:00

95 lines
3.3 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import core.TrajectorySimulator
import core.SimulatorConfig
import core.PhysicsConfig
import core.NoiseConfig
import core.OutputConfig
import resources.data.sampleRoute
/**
* 主程序入口
*
* 演示如何使用 TrajectorySimulator 生成轨迹数据
*
* 完整流程:
* 1. 加载样本轨迹
* 2. 创建模拟器实例
* 3. 配置参数
* 4. 模拟运动
* 5. 输出结果
*/
fun main() {
// ════════════════════════════════════════════
// 第1步准备数据
// ════════════════════════════════════════════
val route = sampleRoute
// ════════════════════════════════════════════
// 第2步创建模拟器
// ════════════════════════════════════════════
val config = SimulatorConfig(
physics = PhysicsConfig(
totalDistance = 2000.0,
duration = 600.0,
maxVelocity = 4.0,
minVelocity = 1.8,
sampleStepSeconds = 1.0,
modelMaxAccelerationMps2 = 1.2,
seed = 42L
),
noise = NoiseConfig(
gpsErrorStdDev = 0.00002,
driftWeight = 0.1
),
output = OutputConfig(
duration = 600.0,
timeStep = 3.0
)
)
val simulator = TrajectorySimulator(route, config)
// ════════════════════════════════════════════
// 第4步模拟运动逐个时间步
// ════════════════════════════════════════════
val timeStep = config.output.timeStep
val duration = config.output.duration // 总模拟时长10分钟
println("时间(秒)\t距离(米)\t速度(m/s)\t加速度(m/s²)\t纬度\t\t经度\t\tGPS误差(m)")
println("".repeat(100))
val routeStates = simulator.routeOut(duration = duration, timeStep = timeStep)
routeStates.forEach { motionState ->
println(
"%.1f\t%.1f\t%.3f\t%.3f\t%.6f\t%.6f\t%.6f".format(
motionState.time,
motionState.distance,
motionState.velocity,
motionState.acceleration,
motionState.latitude,
motionState.longitude,
motionState.gpsError
)
)
}
println("\n模拟完成!")
}
/**
* 伪代码:未来扩展示例
*
* // 例1支持多个样本轨迹
* val simulator2 = TrajectorySimulator(customRoute)
*
* // 例2生成多个轨迹并导出GPX/KML
* val motionStates = mutableListOf<MotionState>()
* for (time in 0.0..duration step timeStep) {
* motionStates.add(simulator.simulate(time))
* }
* GpxExporter.export(motionStates, "output.gpx")
* KmlExporter.export(motionStates, "output.kml")
*
* // 例3统计分析
* val avgVelocity = motionStates.map { it.velocity }.average()
* val maxError = motionStates.map { it.gpsError }.maxOrNull()
*/