Aligning 2D Point Cloud data with X-Axis
Show older comments
Hi,
I have a 2D Point vertices data (with x and y values seperated in each row). I tried using PCA Function first and got the new coordinates. Now,I observed that, slope of PCA Axis is not completely zero with respect to X-Axis. I basically want to align PCA Axis with X-Axis,so that even all those 2D Points in the set,appear to be aligned with X-Axis properly.
I have written the following code:
K = table2array(RawDataUnscaled);
scatter(K(:,1), K(:,2), 'r');
hold on;
EigenMatrix = pca(K);
FinalData = K*EigenMatrix;
scatter(FinalData(:,1), FinalData(:,2), 'b');
The dataset is as follows: [in attached .mat file -- dpb]
1 Comment
dpb
on 30 Oct 2018
Answers (2)
dpb
on 30 Oct 2018
I'll repeat the Comment made in previous followup--
Actually, it's a fignewton of a visual optical illusion effect; if you compute
>> b=polyfit(FinalData(:,1),FinalData(:,2),1)
b =
0.0000 722.7947
>>
the slope IS identically zero; it's just that the extreme points aren't quite symmetric that gives the visual appearance of a rotation.
You'd have to decide another measure of which it is that is the wanted measure of alignment. Perhaps that might be based on finding the locations of the min/max x-coordinates and fitting between those associated y-values altho that would be pretty noise-prone on single points.
What could produce a visual appearance for this particular point cloud probably then would not be so effective for the next with a slightly different noise pattern.
3 Comments
Math Enthusiast
on 30 Oct 2018
dpb
on 30 Oct 2018
I know what you want; sometimes life's just not fair... :)
If you only operate on the point cloud I don't see any way to guarantee it will "look right" to you for all cases.
If you were to fit a given geometric shape to the data and then rotate the shape instead, you could obviously make that shape be aligned; whether it would still pass the appearance test of the data set when superimposed is, still I think, questionable.
I believe (altho I haven't tried it specifically) that the result with the sample data would end up reproducing the rotation as given by the PCA because that is the minimum variance with respect to the revised direction.
Math Enthusiast
on 30 Oct 2018
dpb
on 30 Oct 2018
0 votes
Well, that's somewhat of a different problem statement..
Least-squares_Fitting_of_Polygons is interesting albeit not precisely what you're looking for...
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!