Cumulative distance VS time graph
Mostrar comentarios más antiguos
Hi, I have four arrays that represent a mountain bike run, northing, easting, elevation and time all of size 2507*1, I need to find the cumulative distance of the three positional arrays in km and graph versus time. The corodinates are all in meters atm starting at origin (0,0,0) and time is in seconds starting at 0.
I belive the formula i need to use is d= sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2) however applying this through the three arrays from begining to end has me stuck.
Thanks for any tips
2 comentarios
Jakob B. Nielsen
el 7 de Oct. de 2021
Can you share the code that you have so far? The formula is correct in that it is simply a generalization of the Pythagorean theorem, but if you don't show your work it is very difficult to give you pointers :)
Brendon Moore
el 7 de Oct. de 2021
Editada: Brendon Moore
el 7 de Oct. de 2021
Respuestas (1)
Walter Roberson
el 7 de Oct. de 2021
cumsum(sqrt(diff(x).^2 + diff(y).^2 + diff(z).^2))
4 comentarios
Brendon Moore
el 7 de Oct. de 2021
Editada: Brendon Moore
el 7 de Oct. de 2021
Walter Roberson
el 7 de Oct. de 2021
Yes, you must diff() the arrays, or do the equivalent.
You do not want to find distance relative to the origin. For example if the person goes 1km north, then 1km east, then 1km south, then 1km west, arriving back at the starting point, then you want the distance to show as 4 km, not as 0 km.
You need to find the length of each segment -- and for greatest accuracy, you would hope that the segments are short.
To find the length of a segment, you need to know the start and end coordinates of the segment, x1, y1, z1, and x2, y2, z2, and then you do sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2) to find the length of the segment. Then you move on to the next segment, x2, y2, z2 and x3, y3, z3 so you get segment length sqrt((x3-x2)^2+(y3-y2)^2+(z3-z2)^2) and so on. So at any one point, you are calculating based upon adjacent x, y, z coordinates, and you want the change in x, the change in y, the change in z for the segment -- which is the difference (diff) in x, the difference (diff) in y, the difference (diff) in z. Thus using diff() makes it trivial to calculate the point-to-point changes for all of the segments at the same time, and that makes it easy to find all the segment lengths -- the sqrt() part of what I posted. Then to know the distance from the origin over time, you cumsum() like I posted.
Brendon Moore
el 7 de Oct. de 2021
Walter Roberson
el 7 de Oct. de 2021
Your code is equivalent to
dx = [Northing(1), diff(Northing)];
dy = [Easting(1), diff(Easting)];
dz = [Elevation(1), diff(Elevation)];
Now, suppose your entire data consists of two readings at the same location -- two different times but no movement at all. Then the diff() parts would all be 0, and you would have
dx = [Northing(1), 0];
dy = [Easting(1), 0];
dz = [Elevation(1), 0];
and you would calculate
Displacement(1) = sqrt(Northing(1)^2 + Easting(1)^2 + Elevation(1)^2)
Displacement(2) = sqrt(0^2 + 0^2 + 0^2)
and Distance(1) would be Displacement(1) and Distance(2) would be Displacement(1) + 0
is this justifiable, that the first Distance is the original coordinates? It is only if there is an implied (0,0,0) before the data and an instantaneous movement to the original coordinates (at infinite speed)
Typically it makes a lot more sense to use the initial coordinates as the base point. And in that case, you can use pure diff()
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!