Linear Interpolation of Array Values

Hey all,

Im currently working on a car physics simulation and I am implementing the torque curve (in Nm)/RPM of an MX5. So I created an Array with a step for every 1000RPM so from : 0 RPM to 7000 RPM :

public int[] maxMotorTorqueAtRPM = new int[8] { 0, 80, 169, 196, 210, 215, 195, 0 };           
 // arrayposition * 1000 = RPM > maxMotorTorqueAtRPM

So lets say RPM = 2000, then torque is 169nm
But because the array is in steps of 1000RPM, i would need to use some interpolation to read the
ex. : torque value for 3421 RPM.

So I make a method :

    public float CheckInterpolatedMaxMotorTorqueAtRPM (int []maxMotorTorqueAtRPM, int currentMotorRPM)
    {
        int interpolatedMaxMotorTorqueAtRPM = Mathf.Lerp (I dont know what to here)
    }  

I’ve looked all over the web but I cant seem to find the proper syntax to do this

Image for clarification : alt text

direct link to image

The green dots are the points in the Array, and the purple line is what i want to interpolate.

Thanks,
Olivier Wierda

Just forget about your array and just define your values as an AnimationCurve. Just make a public AnimationCurve variable:

public AnimationCurve motorTorque;

You can simply sample the curve by using Evaluate

float val = motorTorque.Evaluate(rpm);

Keep in mind that you can use actual curves or you can set the tangents to be flat is you really want linear interpolation. However since the torque / rmp curve is actually a curve you probably want to actually make it a curve ^^.