PRINCIPALAXESTRANSFORM Align a set of points along its principal axes. TRANSFO = principalAxesTransform(PTS) Computes the affine transform that will transform the input array PTS such that its principal axes become aligned with main axes. [TRANSFO, PTS2] = principalAxesTransform(PTS) Also returns the result of the transform applied to the points. Example principalAxesTransform See also principalAxes, equivalentEllipse, equivalentEllipsoid
0001 function varargout = principalAxesTransform(pts) 0002 %PRINCIPALAXESTRANSFORM Align a set of points along its principal axes. 0003 % 0004 % TRANSFO = principalAxesTransform(PTS) 0005 % Computes the affine transform that will transform the input array PTS 0006 % such that its principal axes become aligned with main axes. 0007 % 0008 % [TRANSFO, PTS2] = principalAxesTransform(PTS) 0009 % Also returns the result of the transform applied to the points. 0010 % 0011 % Example 0012 % principalAxesTransform 0013 % 0014 % See also 0015 % principalAxes, equivalentEllipse, equivalentEllipsoid 0016 % 0017 0018 % ------ 0019 % Author: David Legland 0020 % E-mail: david.legland@inrae.fr 0021 % Created: 2020-03-06, using Matlab 8.6.0.267246 (R2015b) 0022 % Copyright 2020-2024 INRAE - Cepia Software Platform 0023 0024 % computes principal axes 0025 [center, rotMat] = principalAxes(pts); 0026 0027 % concatenate into affine matrix 0028 nd = size(pts, 2); 0029 transfo = inv([rotMat center'; zeros(1, nd) 1]); 0030 0031 0032 % format output 0033 if nargout < 2 0034 varargout = transfo; 0035 else 0036 if nd == 2 0037 pts2 = transformPoint(pts, transfo); 0038 else 0039 pts2 = transformPoint3d(pts, transfo); 0040 end 0041 varargout = {transfo, pts2}; 0042 end