( point1: THREE.Vector3, point2: THREE.Vector3, targetDistance: number )
| 14 | * Scale is applied uniformly about the midpoint of the two points. |
| 15 | */ |
| 16 | export 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. |
no test coverage detected