Clear Filters
Clear Filters

convhull/convhulln: data is coplanar/data is degenerate in at least one dimension (I know it is, but it is supposed to be.)

5 views (last 30 days)
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!

Accepted Answer

Matt J
Matt J on 15 Aug 2017
Edited: Matt J on 15 Aug 2017
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 Comments
Sterling Baird
Sterling Baird on 26 Jun 2020
Edited: Sterling Baird on 26 Jun 2020
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, k === # pts.
Thank you @Matt J, this was very helpful for what I was trying to do.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 15 Aug 2017
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 Comments
John D'Errico
John D'Errico on 5 Feb 2022
Edited: John D'Errico on 5 Feb 2022
@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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!