Generate points for smooth movement between two given points This is one of the methods in a project for generating points between two given points. We add points of route with a 25ms delay in an array and a camera on Google Maps is always at the last point. So we need to move it smoothly. This method adds those extra points between any two given points to make it move smoothly.

public List&lt;Tuple&lt;double, double&gt;&gt; GeneratePointsForSmoothMovement(double x1, double y1, double x2, double y2, double divider)
{
    // If points are same, return empty list
    if (x1 == x2 &amp;&amp; y1 == y2)
        return new List&lt;Tuple&lt;double, double&gt;&gt;();

    // get difference between x and y cordinates
    double xi = (x2 - x1);
    double yi = (y2 - y1);

    // divide difference into n parts
    xi = xi / divider;
    yi = yi / divider;

    // set new temp vars equal to first point
    double xf = x1;
    double yf = y1;

    // initialize list to save new points
    List&lt;Tuple&lt;double, double&gt;&gt; points = new List&lt;Tuple&lt;double, double&gt;&gt;();

    // increment temp vars by difference-division parts
    for (int i = 0; i &lt; divider; i++)
    {
        xf += xi;
        yf += yi;

        points.Add(Tuple.Create(xf, yf));
    }

    // last cordinate in the list will be equal to point 2
    // return
    return points;
}


Is this the most efficient way ?
Dividor

dividor is ill-defined. It acts as a factor for quantization:


 xi = xi / divider;



But also as threshold for yielding smoothed results:


for (int i = 0; i &lt; divider; i++)



While this seems fine if dividor is \$integer &gt;= 2\$, it could yield unwanted results for fractions (as it is a double precision integer). I would at least change its type to int or uint instead and add an out-of-bound guard. If you would decide to allow fractions, make it clear in the spec how the edge case near the end is handled, since you might get a scenario where you don't synchronize with the end value.



Usability

GeneratePointsForSmoothMovement is a low level generator. The caller code should still think about technical parameters to provide. And if a caller requires several levels of smoothness, multiple calls with different parameters have to be executed. In order to provide the consumer a solution that avoids most overhead, you could write an extension method on IEnumerable&lt;Tuple&lt;Double,Double&gt;&gt; and preferrably also on IDictionary&lt;Double,Double&gt; for faster lookup.

In pseudo code:

public static Func&lt;Double, Double&gt; ToContinuousFunction(
    this IDictionary&lt;Double,Double&gt; points)
{
    return new Func&lt;Double, Double&gt;(x =&gt; 
    {
        if (points.TryGetValue(x, out var y))
        {
            return y;
        }

        // .. perform lineair interpolation or extrapolation based on nearby points
    });
}


Let's say we have points (x: 1, y: 10) and (x: 2, y: 20):

var f = points.ToContiniousFunction();
var yValues = new [] 
{
    f(1)    // 10  (from cache)
   ,f(1.5)  // 15  (interpolation)
   ,f(2)    // 20  (from cache)
   ,f(3)    // 30  (extrapolation)
};