【发布时间】:2020-05-16 15:53:36
【问题描述】:
我正在尝试计算下图中的位置 2。
我从
知道位置 1 this._end = new THREE.Vector3()
this._end.copy( this._rectanglePos )
.sub( this._circlePos ).setLength( 1.1 ).add( this._circlePos )
圆的半径是2.2
我现在正试图沿着这个交叉点计算矩形边缘的位置。
我把 found an equation written in pseudo code 变成了这个函数
function positionAtEdge(phi, width, height){
let c = Math.cos(phi)
let s = Math.sin(phi)
let x = width/2
let y = height/2
if (width * Math.abs(s) < height * Math.abs(c)){
x -= Math.sign(c) * width / 2
y -= Math.tan(phi) * x
}
else{
y -= Math.sign(s) * height / 2
x -= cot(phi) * y
}
return {x, y, z: 0}
function cot(aValue){
return 1/Math.tan(aValue);
}
}
这种方法适用于矩形的顶部,但在 90 度后开始抛出疯狂的值。数学没有 coTan 函数,所以我通过谷歌搜索假设他们的意思是这个 cot 函数。
任何人都知道找到此位置 2 的更简单方法或如何将此功能转换为可用的东西。
【问题讨论】: