首頁(yè)
社區(qū)
課程
招聘
求矩形中心點(diǎn)和邊交點(diǎn)距離

 

以知A-B角度40度,B為矩形中心點(diǎn),怎樣獲取B到A的距離。

 

這個(gè)角度是可變的

收藏
3條回答
AperOdry 2023-1-31

ab=0.5W/sin40度

 

W是矩形的width

回復(fù)
99JW99 2023-1-31

同意樓上,如果你想要代碼格式的,你可以使用下面的javascript:

 

function calculateDistance(angle, width, height) {
const radAngle = angle * Math.PI / 180
return Math.min((width/2) / Math.cos(radAngle), (height / 2) / Math.sin(radangle)) }

回復(fù)
酋長(zhǎng)哥 2023-2-12
1
2
3
4
5
6
import math
 
angle = 40 * math.pi / 180 # convert degrees to radians
height = 100
distance = height / math.tan(angle)
print(distance)
回復(fù)