Cumulative distance VS time graph
이전 댓글 표시
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
Jakob B. Nielsen
2021년 10월 7일
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
2021년 10월 7일
편집: Brendon Moore
2021년 10월 7일
답변 (1개)
Walter Roberson
2021년 10월 7일
cumsum(sqrt(diff(x).^2 + diff(y).^2 + diff(z).^2))
댓글 수: 4
Brendon Moore
2021년 10월 7일
편집: Brendon Moore
2021년 10월 7일
Walter Roberson
2021년 10월 7일
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
2021년 10월 7일
Walter Roberson
2021년 10월 7일
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()
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!