I'm trying to compute the symmetry plane of a 3D mesh representing an animal footprint in R.
I've ran a PCA on the 5755 points that are making up the 3D mesh (see below):
The output of the PCA is the following matrix of variable loadings (i.e., a matrix whose columns contain the eigenvectors):
The question is how can I now link these Principal Components to the symmetry plan (++=) that passes thought the centre of mass of the 3D mesh (i.e. mean x, mean y and mean z)?
I've read many times the following post but unfortunately I couldn't find a solution to my problem: Fitting a plane to a set of points in 3D using PCA
Here is my script (so far):
library(Rvcg)
library(rgl)
path_ply <- "/Volumes/eTrack/eTrack - Segmented 3D models"
filelist_ply1 <- list.files(path_ply, pattern = ".ply",full.names = TRUE)
i=1
filelist_ply1[i]
#Read 3D mesh (.ply)
Specimen <- vcgPlyRead(filelist_ply1[i], updateNormals = TRUE,
clean = TRUE)
#Remove unwanted components
Specimen <- vcgIsolated(
Specimen,
facenum = NULL,
diameter = NULL,
split = FALSE,
keep = 1,
silent = FALSE)
X <- t(Specimen$vb[1:3,])
#Demeaning the variables
mean_vec <- colMeans(X)
X_demeaned <- matrix(NA, ncol = 3, nrow = length(X[,1]))
X_demeaned[, 1] <- X[, 1]-mean_vec[1]
X_demeaned[, 2] <- X[, 2]-mean_vec[2]
X_demeaned[, 3] <- X[, 3]-mean_vec[3]
cov.X=cov(X_demeaned)
eigen_vectors <- eigen((cov.X))$vectors
eigen_values <- eigen((cov.X))$values
eigen_vectors
eigen_values
a <- eigen_vectors[1, 3]
b <- eigen_vectors[2, 3]
c <- eigen_vectors[3, 3]
d <- a * mean_vec[1] + b * mean_vec[2] + c * mean_vec[3]
open3d()
plot3d(X[, 1], X[, 2], X[, 3], type = "p", col = "red", size = 1)
rgl.planes(a, b, c, d, alpha=0.2, color = "#D95F02")