Ваш вопрос касается не только PCA, как о том, как обращаться с точками и линиями в плоскости: точки переключения и точки проецирования на линию. (Для основы этого, посмотрите через SO questions/tagged/2d+geometry, или задать новый вопрос с этими тегами.) Без этих основ, и немного Python или Matlab, эта маленькая программа Python не будет иметь никакого смысла, но здесь в любом случае:
from __future__ import division
import numpy as np # http://www.numpy.org/
def pcabox(Pointcloud, Pca1, Pca2):
""" Lo1, Hi1, Lo2, Hi2 = pcabox(Pointcloud, Pca1, Pca2)
In: Pointcloud: an N x 2 array of points
In: Pca1, Pca2: unit vectors at right angles, from PCA
Out: Lo1, Hi1, Lo2, Hi2: midpoints of the sides of a bounding box
"""
# convert inputs to numpy arrays (if they aren't already) --
Pointcloud = np.asarray(Pointcloud)
Pca1 = np.asarray(pca1)
Pca2 = np.asarray(pca2)
# check N x 2 --
assert Pointcloud.ndim == 2 and Pointcloud.shape[1] == 2, Pointcloud.shape
C = np.mean(Pointcloud, axis=0) # the centre of all the points
Pointcloud = Pointcloud - C # shift the cloud to be centred at [0 0]
# distances along the long axis t * Pca1 --
Dist1 = np.dot(Pointcloud, Pca1)
Lo1 = Dist1.min() * Pca1
Hi1 = Dist1.max() * Pca1
# and along the short axis t * Pca2 --
Dist2 = np.dot(Pointcloud, Pca2)
Lo2 = Dist2.min() * Pca2
Hi2 = Dist2.max() * Pca2
return [Lo1, Hi1, Lo2, Hi2] + C # 4 points
Я предполагаю, что он использует PCL (библиотека pointcloud), и ответ должен использовать классы/функции pcl. – NKN