First, I just want to say I know that "ManhattanDistance" is a built in command for finding the distance between 2 pairs of points. But I have created my own function as follows:
Clear[taxicab, x1, x2, y1, y2];
taxicab[{{x1_, y1_}, {x2_, y2_}}] := Abs[(x2 - x1)] + Abs[(y2 - y1)];
taxicab[{{2, 3}, {1, 4}}]
Now, this is great for 2 pairs of coordinates, but what if I was driving around town (we will use an x,y plane) and go to different locations such as (1,1),(5,2), you get the idea?..I will start at the origin (0,0), go to specific locations defined by coordinates, and then end up back at the origin (0,0) at the end of my journey..I'm trying to create a loop function that can in turn, find the total distance I traveled, regardless of how many coordinates I give it..It's important to know that at the very end, I cannot travel just a straight line back to the origin, because, in real life this would be impossible..
I'm just getting started on some basic ideas but I have hit a wall.. Here is what I have thus far (without even creating the actual loop)
Clear[getdistance, x, y, distance];
distancelength := Length[{{1, 1}, {2, 2}}];
totaldistance[{x2_, y2_}] := Abs[(x2 - 0)] + Abs[(y2 - 0)];
totaldistance[{2, 3}]
In my totaldistance function I have initialized the distance to be the distance between the origin and the first location, great. Now I know I'm going to need to update that totaldistance using a loop..For each location I go to, I must find the new distance (totaldistance + taxicab[current point, previous point]). Lastly I'll need to finalize that totaldistance including distance from last point to the origin, and then have my output be that total distance traveled for all the coordinates..
I just don't understand how I am going to get back the origin at the very end, without traveling in some straight line. I'm just looking for some ideas to get my brain thinking in the right direction. it just wouldn't make sense for me to travel back to the origin using the coordinates (locations). Couldn't I just find the shortest distance to the origin using coordinates that don't just produce a straight line ?