## aim4.vehicle Class VehicleUtil

```java.lang.Object
aim4.vehicle.VehicleUtil
```

`public class VehicleUtilextends Object`

The utility functions for vehicles.

Method Summary
`static double` ```calcDistanceIfAccel(double startVelocity, double accel, double targetVelocity, double duration)```
Determine how far the Vehicle will go in the given duration, if it starts at the given starting velocity and accelerates at the given acceleration toward the provided target velocity.
`static double` ```calcDistanceToStop(double startingVelocity, double maxDeceleration)```
Get the amount of distance it will take to stop, given a starting velocity.
`static double` `distanceToCarInFront(AutoVehicleDriverView vehicle)`
Calculate the distance to the Vehicle in front of this one, in meters.
`static double` ```distanceToChangeBetween(double v0, double vf, double acc)```
Calculate how much distance the Vehicle will cover while changing velocity.
`static double` ```distanceToChangeBetween(double v0, double vf, double acc, double dec)```
Calculate how much distance the Vehicle will cover while changing velocity.
`static boolean` ```intersects(VehicleSimView v, Area area)```
Determine whether the given Vehicle is currently inside an area
`static double` ```maxTurnVelocity(VehicleSpec spec, Lane arrivalLane, Lane departureLane, IntersectionManager im)```
Get the maximum velocity that this Vehicle should make the turn between lanes through an intersection.
`static double` ```maxVelocityToStopOverDistance(VehicleSpec spec, double distance)```
Calculate the maximum starting velocity for which the vehicle can stop within the given distance.
`static double` ```minimumTimeToCover(double distance, double startVelocity, double topVelocity, double acc)```
Calculate the minimum amount of time, in seconds, it can take for the vehicle to cover the indicated distance, given a starting velocity and a top velocity allowed while covering the distance.
`static double` ```timeToChangeBetween(double v0, double vf, double acc)```
Calculate how much time the Vehicle will cover to change velocity with a given acceleration.
`static double` ```timeToChangeBetween(double v0, double vf, double acc, double dec)```
Calculate how much time the Vehicle will cover to change velocity with a given acceleration and a given deceleration

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### maxTurnVelocity

```public static double maxTurnVelocity(VehicleSpec spec,
Lane arrivalLane,
Lane departureLane,
IntersectionManager im)```
Get the maximum velocity that this Vehicle should make the turn between lanes through an intersection. This method relies heavily on two types of caches. First, there is a cache for each instance that is used if the vehicle is a CUSTOM type. Second, there is a cache that belongs to the whole Vehicle class that is indexed by VehicleType, which essentially keeps a shared cache for each VehicleType.

Parameters:
`spec` - the vehicle's specification
`arrivalLane` - the Lane from which the Vehicle is turning
`departureLane` - the Lane into which the Vehicle is turning
`im` - the IntersectionManager controlling the intersection through which the Vehicle is making the turn
Returns:
the maximum safe velocity at which the Vehicle should make the turn

### maxVelocityToStopOverDistance

```public static double maxVelocityToStopOverDistance(VehicleSpec spec,
double distance)```
Calculate the maximum starting velocity for which the vehicle can stop within the given distance.

Parameters:
`spec` - the vehicle specification
`distance` - the distance over which the Vehicle will be changing velocity
Returns:
the maximum starting velocity for which the vehicle can stop within the given distance

### calcDistanceToStop

```public static double calcDistanceToStop(double startingVelocity,
double maxDeceleration)```
Get the amount of distance it will take to stop, given a starting velocity.

Parameters:
`startingVelocity` - the velocity at which the Vehicle starts decelerating
`maxDeceleration` - the maximum deceleration
Returns:
the amount of distance it will take to stop

### calcDistanceIfAccel

```public static double calcDistanceIfAccel(double startVelocity,
double accel,
double targetVelocity,
double duration)```
Determine how far the Vehicle will go in the given duration, if it starts at the given starting velocity and accelerates at the given acceleration toward the provided target velocity.

Parameters:
`startVelocity` - the initial velocity of the Vehicle
`accel` - the acceleration of the Vehicle during this time
`targetVelocity` - the velocity at which the Vehicle will stop accelerating
`duration` - the duration for which this all takes place
Returns:
how far the Vehicle will travel in this time

### timeToChangeBetween

```public static double timeToChangeBetween(double v0,
double vf,
double acc)```
Calculate how much time the Vehicle will cover to change velocity with a given acceleration.

Parameters:
`v0` - the initial velocity of the Vehicle
`vf` - the final velocity of the Vehicle
`acc` - the acceleration
Returns:
the time it will take the Vehicle to change between the two given velocities

### timeToChangeBetween

```public static double timeToChangeBetween(double v0,
double vf,
double acc,
double dec)```
Calculate how much time the Vehicle will cover to change velocity with a given acceleration and a given deceleration

Parameters:
`v0` - the initial velocity of the Vehicle
`vf` - the final velocity of the Vehicle
`acc` - the acceleration
`dec` - the deceleration
Returns:
the time it will take the Vehicle to change between the two given velocities

### distanceToChangeBetween

```public static double distanceToChangeBetween(double v0,
double vf,
double acc)```
Calculate how much distance the Vehicle will cover while changing velocity.

Parameters:
`v0` - the initial velocity of the Vehicle
`vf` - the final velocity of the Vehicle
`acc` - the acceleration
Returns:
the distance covered by the Vehicle while changing between the two given velocities

### distanceToChangeBetween

```public static double distanceToChangeBetween(double v0,
double vf,
double acc,
double dec)```
Calculate how much distance the Vehicle will cover while changing velocity.

Parameters:
`v0` - the initial velocity of the Vehicle
`vf` - the final velocity of the Vehicle
`acc` - the acceleration
`dec` - the deceleration
Returns:
the distance covered by the Vehicle while changing between the two given velocities

### minimumTimeToCover

```public static double minimumTimeToCover(double distance,
double startVelocity,
double topVelocity,
double acc)```
Calculate the minimum amount of time, in seconds, it can take for the vehicle to cover the indicated distance, given a starting velocity and a top velocity allowed while covering the distance.

Parameters:
`distance` - the distance to cover
`startVelocity` - the velocity at the start of covering the distance
`topVelocity` - the top allowed velocity while covering the distance
`acc` - the acceleration
Returns:
the minimum amount of time, in seconds, to cover the distance

### intersects

```public static boolean intersects(VehicleSimView v,
Area area)```
Determine whether the given Vehicle is currently inside an area

Parameters:
`v` - the Vehicle
`area` - the area
Returns:
whether the Vehicle is currently in the area

### distanceToCarInFront

`public static double distanceToCarInFront(AutoVehicleDriverView vehicle)`
Calculate the distance to the Vehicle in front of this one, in meters. Uses either the supplied distance in the intervalometer or the laser range finder, depending on whether the laser range finder is activated or not.

Parameters:
`vehicle` - the vehicle
Returns:
the distance to the Vehicle in front of this one, in meters