Hi James-1709,
You can use the Math.Sqrt function to calculate the distance of each segment according to the coordinates, and then calculate the time of each segment with the known speed.
Here is a simple code example:
List<float> time = new List<float>();
List<Point> pointsOfList = new List<Point>();
private void Form1_Load(object sender, EventArgs e)
{
pointsOfList.Add(new Point(1, 2));
pointsOfList.Add(new Point(3, 4));
pointsOfList.Add(new Point(5, 6));
pointsOfList.Add(new Point(7, 8));
pointsOfList.Add(new Point(9, 10));
for (int i=0;i<pointsOfList.Count-1;i++)
{
var t = GetTime(i, i+1);
time.Add(t);
}
}
public float GetTime(int startIndex, int endIndex)
{
float speed = 0.5f;
float S1 = GetDistance(pointsOfList[startIndex], pointsOfList[endIndex]);
float t1 = S1 / speed;
return t1;
}
public static float GetDistance(Point startPoint, Point endPoint)
{
int x = System.Math.Abs(endPoint.X - startPoint.X);
int y = System.Math.Abs(endPoint.Y - startPoint.Y);
return (float)Math.Sqrt(x * x + y * y);
}
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.