0

Data which available for computation is

  1. Driver (lat,lon) x mins
  2. customer (lat,lon) x - millisecond
  3. Driver (lat,lon) x-1 mins
  4. Driver (lat,lon) x-2 mins

I have set of location in which i want to find the whether car is moving towards or moving away from a customer .

Data which i have is customer location and car's last 3 polled location (which use to push each minutes).

There is two method in which i can find .

  1. Distance calculation.
  2. Angle in which car moved.

Which would be the best way to go . Do both method required to be combined if so, how some glance ?

Syed Abdul Kather
  • 608
  • 2
  • 12
  • 29
  • 1
    What do you mean by "assigned"? Is the assignment to a driver somhow relevant for the task? What is stopping you from simply calculating the distance from the person for the three positions and checking if it in- or decreases? – Alexander Weinert May 28 '15 at 08:58
  • Ditto, also consider that distance in a city is probably not the euclidian one, since the car will have to follow streets... – Anders R. Bystrup May 28 '15 at 09:02

1 Answers1

0

Moving towards a customer = getting closer = distance is less than it was.

public static void main(String[] args) {


    double personX = 1, personY = 1;
    double carX1 = 4, carY1 = 4;
    double carX2 = 2, carY2 = 3;

    if (distance(personX, personY, carX1, carY1) > distance(personX, personY, carX2, carY2)) {
        System.out.println("Getting closer");
    }
}

static double distance(double x1, double y1, double x2, double y2) {
    double dx = x1 - x2;
    double dy = y1 - y2;
    return Math.sqrt(dx*dx + dy*dy);
}
rghome
  • 8,529
  • 8
  • 43
  • 62