1樓:
寫了個蒙特卡洛的。
import
numpy
asnp
from
random
import
random
import
matplotlib.pyplot
asplt
defplot_rectangle(A
:np.ndarray,B
:np.ndarray):x
=[A[
0],B[
0],B[
0],A[
0],A[
0]]y=
[A[1
],A[1
],B[1
],B[1
],A[1
]]plt
.plot(x
,y)def
not_same_sign(a
,b)->
bool
:return(a
<0)^(b<0)
class
trangle
():def
__init__
(self,A
:np.ndarray,B
:np.ndarray,C
:np.ndarray
):self
.points=np
.array([A
,B,C
])self
.vectors=np
.array([B
-A,C
-B,A
-C])def
if_in
(self
,point:np
.ndarray
)->bool
:prev_product=np
.cross
(self
.vectors[0
],point
-self
.points[0
])foriin
range(1
,3):curr_product=np
.cross
(self
.vectors[i
],point
-self
.points[i
])if
not_same_sign
(prev_product
,curr_product
):return
False
return
True
defrange
(self
)->np.
ndarray
:returnnp.
array
([np
.min
(self
.points
,axis=0
),np
.max
(self
.points
,axis=0
)])defplot_trangle
(self):x
,y=self
.points
[:,0
],self
.points
[:,1
]plt
.scatter(x
,y)plt
.plot(np
.hstack((x
,x[0
])),np.
hstack((y
,y[0
])))
defcal_overlap
(trangleA
:trangle
,trangleB
:trangle
)->float
:repeat_time
=10000
count=0
range_A
=trangleA
.range
()range_B
=trangleB
.range
()range_here=np
.array
([np
.min(np
.vstack
((range_A[0
],range_B[0
])),
axis=0
),np
.max(np
.vstack
((range_A[1
],range_B[1
])),
axis=0
)])plot_rectangle
(range_here[0
],range_here[1
])range_span
=range_here[1
]-range_here[0
]range_here_S
=range_span[1
]*range_span[0
]foriin
range
(repeat_time
):random_point
=range_span*np
.random
.random(2
)+range_here[0
]iftrangleA
.if_in
(random_point
)and
trangleB
.if_in
(random_point
):# plt.scatter(random_point[0], random_point[1], s = 20
# plt.pause(0.001)
count+=1
# plt.show()
return
count
/repeat_time
*range_here_S
if__name__
=='__main__'
:test
=trangle(np
.array([0
,0]),np
.array([3
,0]),np
.array([3
,4]))
test_1
=trangle(np
.array([1
,-1]),np.
array([3
,0]),np
.array([3
,4]))
test
.plot_trangle
()test_1
.plot_trangle
()check
=cal_overlap
(test
,test_1
(check
)把注釋掉的三句取消注釋就能看到視覺化過程。
這樣的三角形怎麼求角度?
keghost x 30 1,正餘弦定理暴力求解。此法雖簡單,但過程一般煩瑣2,角平分線定理的運用,選取輔助線 3,正三角形極其相關知識的運用,選取輔助線 夜風 我也在知乎提問這個問題了,貼了一些大神給我的回覆https www. SneakerHead Rio 學霸男友給我的提示證紅綠倆三角形全等...
如何簡潔明瞭地證明圖中的三角形為正三角形
三千弱水 這是IBM研究院1998年的一道智力題 官方解答一 官方解答二 官方解答三 官方解答四 禿頭披風俠 提供乙個反證法證明。若不是等邊三角形,不妨設 angle B angle C eeimg 1 可得 AC AB eeimg 1 因此 CF eeimg 1 顯然 angle B angle ...
為什麼兩個三角形三條邊就全等?
假設有兩個三角形的三邊相等,但是它們不全等。我們使其中相等的兩條邊重合,並使除了重合邊的端點以外的另外一組頂點落在重合邊的同側,相等的對應邊也落在同側。由於平移 旋轉 對稱後的圖形與原圖形全等,這是可以做到的 不失一般性地,設這兩個三角形分別是 ABC和 DBC,BC為重合邊,AB DB,AC DC...