How do you cluster lines in 3D space?

5 views (last 30 days)
Nathan
Nathan on 23 Aug 2023
Edited: Nathan on 23 Aug 2023
Say you have the time and position of 9 samples.
A=[1:11; 1:11; 1:11];
B(1:3,1:11)=6;
C=flip(A,2);
mynoise=rand(3,11)*.75;
A=A+mynoise;
B=B+mynoise;
C=C+mynoise;
plot([A' B' C'])
How would you cluster/group these lines/paths into 3 different groups? I have been clustering at each timepoint and then connecting the cluster to the closest cluster from i-1, but that falls apart at i=6.
My real data is ankle position while walking on a treadmill. The ankle goes up/down, forward/back, in/out, and over time traces out corkscrews in x,y,z,t space. But after hundreds of steps by many subjects we have noticed some step paths are more "circular", some "triangular", and others "oval."
But I don't want to fit the data to my pre-concieved shapes, I want the data to determine the clusters. How do you cluster in x,y,z space where the clusters are linked/determined from the clusters from t-1 and t+1?
  2 Comments
Matt J
Matt J on 23 Aug 2023
Edited: Matt J on 23 Aug 2023
We would have to know more about how the curves arise, and any specifics about the model they follow. Once curves intersect, there is no general way to know which post-intersection samples associate with which pre-intersection samples.

Sign in to comment.

Answers (1)

Les Beckham
Les Beckham on 23 Aug 2023
I would suggest something like this since the main difference in your "groups" seems to be the approximate slopes of the three groups of lines.
Of course, this may not be appropriate for your real data. If you share an example of the real data it would help in determining an appropriate approach.
A=[1:11; 1:11; 1:11];
B(1:3,1:11)=6;
C=flip(A,2);
mynoise=rand(3,11)*.75;
A=A+mynoise;
B=B+mynoise;
C=C+mynoise;
% plot([A' B' C'])
D = [A' B' C'];
plot(D)
grid on
figure
[Fx, Fy] = gradient(D);
plot(Fy)
grid on
slopes = mean(Fy, 1) % average slope of each of the 9 lines
slopes = 1×9
1.0742 0.9861 1.0266 0.0742 -0.0139 0.0266 -0.9258 -1.0139 -0.9734
groups = discretize(slopes, [-inf -0.5 0.5 inf]) % assign the lines to a group based on average slope
groups = 1×9
3 3 3 2 2 2 1 1 1

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!