public double distBetweenTwoPoints(CO a, CO b) { double deltaX = a.x - b.x; double deltaY = a.y - b.y; return(Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2))); }
public CO convertStringToCo(string point) { var coPoint = new CO(); string value = ""; foreach (char letter in point) { switch (letter) { case '(': case ')': continue; case ',': coPoint.x = Convert.ToDouble(value); value = ""; break; default: value += letter; break; } } coPoint.y = Convert.ToDouble(value); return(coPoint); }
public int indexOfShortest(CO robot, List <CO> availRobots) { var distances = new List <double>(); foreach (CO otherRobot in availRobots) { distances.Add(distBetweenTwoPoints(robot, otherRobot)); } int smallestIndex = 0; double smallestValue = distances[0]; for (int x = 1; x < availRobots.Count; x++) { if (distances[x] < smallestValue) { smallestIndex = x; smallestValue = distances[x]; } } return(smallestIndex); }