convhull/convhulln: data is coplanar/data is degenerate in at least one dimension (I know it is, but it is supposed to be.)
8 次查看(过去 30 天)
显示 更早的评论
Hi there! I have got some data that represents points on planes that are oriented somehow in three dimensional space. As such, the data is coplanar by nature. I want to calculate the area that is covered on the plane on which the data is located, but convhull and convhulln both refuse to do this. I assume the problem is that it would try to calculate a volume which would always come out to zero. Can I force the calculation to get the area or do I need to project the data into a 2D coordinate system first? cheers!
0 个评论
采纳的回答
Matt J
2017-8-15
编辑:Matt J
2017-8-15
Yes, you do have to project them, but it's not too hard. Assumings "points" is an Nx3 array,
[U,S]=svd( bsxfun(@minus,points,mean(points)), 0);
[~,area]=convhull(U*S(:,1:2));
3 个评论
Sterling Baird
2020-6-26
编辑:Sterling Baird
2020-6-26
If you add more points to the "compressed" plane, the way to convert up to 3D is:
[U,S,V]=svd(bsxfun(@minus,pts,mean(pts)),0); % pts == U*S*V'
subdivpts = [0.5 0.5; 1 1; 1 0.5; 2 2]; %define new subdivised (2D) points
newpts = padarray(subdivpts,[0 1],'post')*V'+mean(pts); %add column of zeros to get new U*S, then post-multiply by V'
Note that this is also general to compressing/projecting/compacting a hyperplane from n to n-1 dimensions, where the only change is that pts and divpts are k x n matrices, .
Thank you @Matt J, this was very helpful for what I was trying to do.
更多回答(1 个)
Image Analyst
2017-8-15
Can you attach the data?
One approach might be to get a rotated coordinate system with pca(). Then ignore the coordinate along the thin direction and get the convex hull from that 2-D projection. Then use polyarea() to get the area.
For example, let's say you have a wide expanse in the x and y direction and some but very little in the z direction. Then pass just a and y into convhull() and take the returned points and pass those points only into polyarea. pca() is just the same except it will handle tilted planes, not just those aligned with the axes, because it defines new axes.
Hope you followed that - you probably will if you know about principal components analysis.
I attach my only pca demo, though it doesn't do exactly what you want, but perhaps it might be instructive nonetheless.
3 个评论
Sterling Baird
2022-2-5
@Image Analyst or @Matt J could you comment on how the solution suggested by @Matt J differs from PCA? (or is it identical?)
John D'Errico
2022-2-5
编辑:John D'Errico
2022-2-5
@Sterling Baird - The use of SVD there on the mean subtracted data makes it the same as PCA, assuming the projection via SVD is done into the plane of the first two components from PCA. In fact, one can do PCA enirely from the output from SVD, but use of PCA is a little more friendly to someone who does not truly understand the mathematics required to build such a tool.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!