threejs 计算点到直线的距离
/**
* 获取点到直线的距离
* @param {THREE.Vector3} point
* @param {THREE.Vector3} linePointA
* @param {THREE.Vector3} linePointB
* @returns
*/
getPointToLineDistance(point, linePointA, linePointB) {
// 向量ApB构建一个三角形,计算三角形面积
const a = linePointA.clone().sub(point);
const b = linePointB.clone().sub(point);
const c = a.clone().cross(b);
const S = 0.5 * c.length();
// 计算三角形ApB底边AB的长度
const AB = linePointB.clone().sub(linePointA);
const width = AB.length();//AB两点距离
// 计算三角形高度(点到直线的距离)
const H = S / width * 2;
return H
}