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<Tuple<double, double>> GeneratePointsForSmoothMovement(double x1, double y1, double x2, double y2, double divider)
{
// If points are same, return empty list
if (x1 == x2 && y1 == y2)
return new List<Tuple<double, double>>();
// 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<Tuple<double, double>> points = new List<Tuple<double, double>>();
// increment temp vars by difference-division parts
for (int i = 0; i < 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 ?
divider
. Start slow atx1, y1
, accelerate, brake, stop atx2, y2
. \$\endgroup\$ – Eric Duminil Sep 4 '19 at 11:38