Cumulative distance VS time graph
조회 수: 18 (최근 30일)
이전 댓글 표시
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 :)
답변 (1개)
Walter Roberson
2021년 10월 7일
cumsum(sqrt(diff(x).^2 + diff(y).^2 + diff(z).^2))
댓글 수: 4
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()
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!