MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / computeDistanceScale

Function computeDistanceScale

src/utils/sim3dAlignment.ts:16–38  ·  view source on GitHub ↗
(
  point1: THREE.Vector3,
  point2: THREE.Vector3,
  targetDistance: number
)

Source from the content-addressed store, hash-verified

14 * Scale is applied uniformly about the midpoint of the two points.
15 */
16export function computeDistanceScale(
17 point1: THREE.Vector3,
18 point2: THREE.Vector3,
19 targetDistance: number
20): Sim3d {
21 const currentDistance = point1.distanceTo(point2);
22
23 if (currentDistance < 1e-10) {
24 return identitySim3d();
25 }
26
27 const scale = targetDistance / currentDistance;
28 const midpoint = new THREE.Vector3()
29 .addVectors(point1, point2)
30 .multiplyScalar(0.5);
31 const translation = midpoint.clone().multiplyScalar(1 - scale);
32
33 return {
34 scale,
35 rotation: new THREE.Quaternion(),
36 translation,
37 };
38}
39
40/**
41 * Compute translation transform to move a point to the world origin.

Callers 3

align_save.test.tsFile · 0.85

Calls 2

identitySim3dFunction · 0.70
cloneMethod · 0.45

Tested by

no test coverage detected