You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
298 B
JavaScript
11 lines
298 B
JavaScript
import { Vec3 } from './math.js'
|
|
|
|
export function enforceDistance(p1, p2, targetDistance) {
|
|
const v = Vec3.sub(p2, p1)
|
|
const d = Vec3.norm2(v)
|
|
|
|
const factor = (d - targetDistance) / d
|
|
|
|
return [Vec3.add(p1, Vec3.scale(v, 0.5 * factor)), Vec3.add(p2, Vec3.scale(v, -0.5 * factor))]
|
|
}
|