From 9870cb4082d0949f939290846d5213a5c7283b13 Mon Sep 17 00:00:00 2001
From: midlik <midlik@gmail.com>
Date: Fri, 17 Feb 2023 19:08:21 +0000
Subject: [PATCH] Fixed degenerate case (1-point) in PCA (#725)

* Fixed degenerate case (1-point) in PCA - now correctly returns identity matrix

* Changelog
---
 CHANGELOG.md                                         | 1 +
 src/mol-math/linear-algebra/matrix/principal-axes.ts | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index fba2bd395..7948192c6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ Note that since we don't clearly distinguish between a public and private interf
 ## [Unreleased]
 
 Fix impostor bond visuals not correctly updating on `sizeFactor` changes
+Fix degenerate case in PCA
 
 ## [v3.31.2] - 2023-02-12
 
diff --git a/src/mol-math/linear-algebra/matrix/principal-axes.ts b/src/mol-math/linear-algebra/matrix/principal-axes.ts
index 1150702a4..90091e1e1 100644
--- a/src/mol-math/linear-algebra/matrix/principal-axes.ts
+++ b/src/mol-math/linear-algebra/matrix/principal-axes.ts
@@ -27,7 +27,7 @@ namespace PrincipalAxes {
 
     export function calculateMomentsAxes(positions: NumberArray): Axes3D {
         if (positions.length === 3) {
-            return Axes3D.create(Vec3.fromArray(Vec3(), positions, 0), Vec3.create(1, 0, 0), Vec3.create(0, 1, 0), Vec3.create(0, 1, 0));
+            return Axes3D.create(Vec3.fromArray(Vec3(), positions, 0), Vec3.create(1, 0, 0), Vec3.create(0, 1, 0), Vec3.create(0, 0, 1));
         }
 
         const points = Matrix.fromArray(positions, 3, positions.length / 3);
@@ -143,4 +143,4 @@ namespace PrincipalAxes {
 
         return Axes3D.create(origin, dirA, dirB, dirC);
     }
-}
\ No newline at end of file
+}
-- 
GitLab