Unadjusted Exit Velocity

An unadjusted exit velocity is chosen by the game before being adjusted for the player power and other factors.

## Algorithm

1. Calculate the ball's contact position with the bat on a scale from 0 to 200, with 0 being closest to the handle of the bat and 200 being closest to the end.
2. Define the thresholds between contact zone types on the bat (sour near, nice near, perfect, nice far, sour near). The full calculation can be found here: *coming soon*.
3. Using the zone the ball was hit in, choose the upper and lower bounds of the Unadjusted Exit Velocity.
4. Use the ball's contact position to linearly interpolate between the velocity ranges to select the Unadjusted Exit Velocity.

The details are found below.

### Step 1: Calculate ball contact position

The spot where the ball contacts the bat is converted to a range of 0 to 200 based on the x coordinates of the batter and the ball.

1. Subtract the batter's x coordinate from the ball's x coordinate.
2. If the batter is a lefty, multiply by -1. This is basically how far the ball is from the batter.
3. Center the value around 100 with the scale based on the batter's hitting ranges (found at the bottom of the article). Do this by using the first formula if the value is positive, and use the second formula if the value is negative:
	1. 100\*(result from step 2/batter's far horizontal limit) + 100
	2. -100\*(result from step 2/batter's near horizontal limit) - 100
4. Restrict the value from step 3 to be between 0 and 200 if it's out of that range.

### Step 2: Define the Range for Each Type of Contact

Each contact type range (sour near, nice near, perfect, nice far, sour near) is given a length on the bat, and each of them are partitioned by thresholds calculated by the game to determine how long each contact range is. The exact values for each threshold can be found here: *coming soon*. For the purposes of this calculation, the thresholds will be defined as follows in order from nearest to the handle to the end of the bat.

* Minimum value: 0
* Threshold 1: between the sour near and nice near contact zones
* Threshold 2: between the nice near and perfect contact zones
* Absolute perfect: 100
* Threshold 3: between the perfect and nice far contact zones
* Threshold 4: between the nice far and sour far contact zones
* Maximum value: 200

These thresholds are used to define the quality of contact (Sour, Nice, Perfect) used in step 3 and for the linear interpolation in step 4.

### Step 3: Choose the Range of Unadjusted Exit Velocities

The range of possible exit velocities before adjustments is determined by the swing type and the contact type. These factors also select an added gravity factor, but this doesn't directly influence the exit velocity calculation.

Slap hit unadjusted exit velocity ranges
 Nice
 Perfect

Charge hit unadjusted exit velocity ranges
 Nice
 Perfect

### Step 4: Linearly Interpolate the Exit Velocity

After the range above is chosen, the exact value chosen from that range is linearly interpolated by how close the ball contact was from reaching the next highest range (or in the case of perfect, how close the ball was from hitting the absolute perfect pixel).

#### Linear interpolation factor formulas

The linear interpolation factor is basically the percentage towards the upper end of the contact type range\*. For each range, the specific calculations defined by the thresholds are defined below.

\*The calculation isn't a pure linear interpolation for the perfect zone since it is split in the middle by 100. If thresholds 2 and 3 are equally far from 100, the max value of the factor is 0.5, instead of the usual 1. However, the thresholds aren't necessarily symmetric, so the value can be above 0.5 (but never greater than 1)

* Near Sour: Ball contact position / Threshold 1
* Near Nice: (Ball contact position - Threshold 1) / (threshold 2 - Threshold 1)
* Perfect (near side): (Ball contact position - Threshold 2) / (Threshold 3 - Threshold 2)
* Perfect (far side): (Threshold 3 - Ball Contact Position) / (Threshold 3 - Threshold 2)
* Far Nice: (Threshold 4 - Ball Contact Position) / (Threshold 4 - Threshold 3)
* Far Sour: (200 - Ball Contact Position) / (200 - Threshold 4)