0

I am struggling with PCA.

Problem statement: I have two geometries. Both are same, but one of them is rotated around Y axis as shown below.

X1 = [0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 2, 1, 2, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 2, 1, 2]
Y1 = [0, 1, 1, 2, 2, 3, 3, 2, 1, 0, 0, 0, 1, 0, 1, 1, 2, 2, 3, 3, 2, 1, 0, 0, 0, 1]
Z1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

enter image description here

X2 = [0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 2.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 2.0, 1.0, 0.0, 0.0, 0.0, 1.0]
Y2 = [0.0, 0.94, 0.94, 1.88, 1.88, 2.82, 2.82, 1.88, 0.94, 0.0, 0.0, 0.0, 0.94, -0.34, 0.6, 0.6, 1.54, 1.54, 2.48, 2.48, 1.54, 0.6, -0.34, -0.34, -0.34, 0.6]
Z2 = [0.0, 0.34, 0.34, 0.68, 0.68, 1.03, 1.03, 0.68, 0.34, 0.0, 0.0, 0.0, 0.34, 0.94, 1.28, 1.28, 1.62, 1.62, 1.97, 1.97, 1.62, 1.28, 0.94, 0.94, 0.94, 1.28]

enter image description here

I need both two geometries are placed at same orientation after I apply PCA on both geometries.

What I have done:

First I Centered the data.

df_1 = df_1.drop('node_number', axis=1)

Then I applied PCA from sklearn

from sklearn.decomposition import PCA
  
pca = PCA()

pca.fit(data_centered)                                    

pca_scores = pca.transform(data_centered)

scores_df = pd.DataFrame(pca_scores)

scores_df = scores_df.set_axis(['PC1', 'PC2', 'PC3'], axis=1)

scores_df = scores_df.round(2)

I applied this process on first geometry. After first geometry, I have applied this process similary on second geometry also.

But after applying PCA, I have got different new coordinates (X, Y, Z).

coordinate of First geometry after PCA,

X1_new = [-2.12, -1.41, -0.71, 0.0, 0.71, 1.41, 2.12, 1.41, 0.71, -0.0, -0.71, -1.41, -0.0, -2.12, -1.41, -0.71, 0.0, 0.71, 1.41, 2.12, 1.41, 0.71, -0.0, -0.71, -1.41, -0.0]
Y1_new = [-0.38, -1.09, -0.38, -1.09, -0.38, -1.09, -0.38, 0.33, 1.03, 1.74, 1.03, 0.33, 0.33, -0.38, -1.09, -0.38, -1.09, -0.38, -1.09, -0.38, 0.33, 1.03, 1.74, 1.03, 0.33, 0.33]
Z1_new = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5]

enter image description here

coordinate of second geometry after PCA,

X2__new =[-1.74, -0.33, -0.33, 1.09, 1.09, 2.5, 2.5, 1.09, -0.33, -1.74, -1.74, -1.74, -0.33, -1.74, -0.33, -0.33, 1.09, 1.09, 2.5, 2.5, 1.09, -0.33, -1.74, -1.74, -1.74, -0.33]
Y2_new = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5]
Z2_new = [0.0, -0.0, -0.0, -0.0, -0.0, 0.0, 0.0, -0.0, -0.0, 0.0, 0.0, 0.0, -0.0, 0.0, -0.0, -0.0, -0.0, -0.0, 0.0, 0.0, -0.0, -0.0, 0.0, 0.0, 0.0, -0.0]

enter image description here

What I am doing wrong? I need both geometries oriented in a same way. And I cant understand why there is all 0 in Z2_new of 2nd geometry after PCA.

Urvesh
  • 331
  • 4
  • 15
  • see related: [3D OBB approximation](https://stackoverflow.com/a/62284464/2521214) and [Problem superimposing and aligning 3D triangles](https://stackoverflow.com/a/52163563/2521214) – Spektre Sep 28 '22 at 18:34

0 Answers0