Here you can find the source of calcDistanceToStop(double startingVelocity, double maxDeceleration)
Parameter | Description |
---|---|
startingVelocity | the velocity at which the Vehicle starts decelerating |
maxDeceleration | the maximum deceleration |
public static double calcDistanceToStop(double startingVelocity, double maxDeceleration)
//package com.java2s; public class Main { /**/*from w w w. j av a 2 s.c o m*/ * Get the amount of distance it will take to stop, given a starting * velocity. * * @param startingVelocity the velocity at which the Vehicle starts * decelerating * @param maxDeceleration the maximum deceleration * @return the amount of distance it will take to stop */ public static double calcDistanceToStop(double startingVelocity, double maxDeceleration) { // distance to stop is - v ^2 / 2 * a return (-1.0) * startingVelocity * startingVelocity / (2.0 * maxDeceleration); } }