( normal: [number, number, number], centroid: [number, number, number], targetUp: THREE.Vector3 )
| 111 | * and translates it to pass through the origin. |
| 112 | */ |
| 113 | export function computePlaneAlignment( |
| 114 | normal: [number, number, number], |
| 115 | centroid: [number, number, number], |
| 116 | targetUp: THREE.Vector3 |
| 117 | ): Sim3d { |
| 118 | const normalVec = new THREE.Vector3(normal[0], normal[1], normal[2]).normalize(); |
| 119 | const centroidVec = new THREE.Vector3(centroid[0], centroid[1], centroid[2]); |
| 120 | |
| 121 | const rotation = new THREE.Quaternion().setFromUnitVectors(normalVec, targetUp.clone().normalize()); |
| 122 | const rotatedCentroid = centroidVec.clone().applyQuaternion(rotation); |
| 123 | const distanceAlongAxis = rotatedCentroid.dot(targetUp); |
| 124 | const translation = targetUp.clone().multiplyScalar(-distanceAlongAxis); |
| 125 | |
| 126 | return { rotation, translation, scale: 1 }; |
| 127 | } |
no test coverage detected