// Calculates the travel time in milliseconds between two points with given speed.
// Traveling is implemented like a simple time.Sleep from our side.
func calculateMissionTravelTime(source, target *vec2d.Vector, waypoints []*vec2d.Vector, speed int64) time.Duration {
	var distance float64
	prevPoint := source
	distance = 0
	for _, point := range waypoints {
		distance += vec2d.GetDistance(prevPoint, point)
		prevPoint = point
	}
	distance += vec2d.GetDistance(prevPoint, target)
	return time.Duration(distance / float64(speed) * 100)
}
Beispiel #2
0
func ExampleGetDistance() {
	vector := vec2d.New(2.0, 4.0)
	other := vec2d.New(5.0, 12.0)
	distance := vec2d.GetDistance(vector, other)

	fmt.Printf("Vector{X: %v, Y: %v}\n", vector.X, vector.Y)
	fmt.Printf("Vector{X: %v, Y: %v}\n", other.X, other.Y)
	fmt.Printf("Distance between: %v\n", distance)
	// Output:
	// Vector{X: 2, Y: 4}
	// Vector{X: 5, Y: 12}
	// Distance between: 8.54400374531753
}
// Calculates the travel time in milliseconds between two points with given speed.
// Traveling is implemented like a simple time.Sleep from our side.
func calculateSegmentTravelTime(source, target *vec2d.Vector, speed int64) time.Duration {
	distance := vec2d.GetDistance(source, target)
	return time.Duration(distance / float64(speed) * 100)
}