Aligning 2D Point Cloud data with X-Axis

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]

Answers (2)

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

I want something like the attached Image and I am not sure,what exactly needs to be done.I want my square to be exactly aligning with the X-Axis,so that, for a given contour data of Square, I can set the orientation right.
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.
The whole problem statement, itself,is to find out the shape from this vertex data :(..May be,my procedure is not correct. With the given vertex data,can we predict the best possible shapes like Line,circle,square,ellipse,arc? Could you explain some best possible shape detection algorithm for this.

Sign in to comment.

dpb
dpb on 30 Oct 2018
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

Asked:

on 30 Oct 2018

Answered:

dpb
on 30 Oct 2018

Community Treasure Hunt

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

Start Hunting!