MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / principalFrame

Function principalFrame

graph-ui/src/galaxy/camera-frame.ts:320–415  ·  view source on GitHub ↗
(points: readonly Vector3Like[])

Source from the content-addressed store, hash-verified

318 * NaN in die Kamera schreibt, waere ein schwarzes Bild ohne Meldung.
319 */
320export function principalFrame(points: readonly Vector3Like[]): PrincipalFrame {
321 const usable: Vector3Like[] = [];
322 for (const point of points) {
323 if (Number.isFinite(point.x) && Number.isFinite(point.y) && Number.isFinite(point.z)) {
324 usable.push(point);
325 }
326 }
327 if (usable.length === 0) {
328 return { center: ZERO, axes: IDENTITY, extents: [0, 0, 0], counted: 0 };
329 }
330
331 let mx = 0;
332 let my = 0;
333 let mz = 0;
334 for (const point of usable) {
335 mx += point.x;
336 my += point.y;
337 mz += point.z;
338 }
339 mx /= usable.length;
340 my /= usable.length;
341 mz /= usable.length;
342
343 const covariance = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
344 for (const point of usable) {
345 const d = [point.x - mx, point.y - my, point.z - mz];
346 for (let i = 0; i < 3; i += 1) {
347 for (let j = 0; j < 3; j += 1) {
348 (covariance[i] as number[])[j] =
349 ((covariance[i] as number[])[j] as number) + (d[i] as number) * (d[j] as number);
350 }
351 }
352 }
353 for (let i = 0; i < 3; i += 1) {
354 for (let j = 0; j < 3; j += 1) {
355 (covariance[i] as number[])[j] = ((covariance[i] as number[])[j] as number) / usable.length;
356 }
357 }
358
359 const { vectors } = jacobiEigen(covariance);
360 const candidates: Vector3Like[] = [0, 1, 2].map((column) => orient(norm({
361 x: (vectors[0] as number[])[column] as number,
362 y: (vectors[1] as number[])[column] as number,
363 z: (vectors[2] as number[])[column] as number,
364 })));
365
366 /*
367 * Gemessen wird die Ausdehnung, danach wird sortiert.
368 *
369 * Der Eigenwert waere die Varianz, und die kann bei einer Wolke mit einem
370 * dichten Kern und wenigen Ausreissern eine andere Reihenfolge ergeben als
371 * der Kasten. Ins Bild muss der Kasten.
372 */
373 const measured = candidates.map((axis) => {
374 let min = Number.POSITIVE_INFINITY;
375 let max = Number.NEGATIVE_INFINITY;
376 for (const point of usable) {
377 const value = dot(point, axis);

Callers 2

fitCameraFunction · 0.85

Calls 7

jacobiEigenFunction · 0.85
orientFunction · 0.85
alongFunction · 0.85
normFunction · 0.70
dotFunction · 0.70
crossFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected