第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 PyGame 顯示 Sci Py voronoi 邊緣會產(chǎn)生奇怪的“星星”效果

使用 PyGame 顯示 Sci Py voronoi 邊緣會產(chǎn)生奇怪的“星星”效果

江戶川亂折騰 2021-12-09 10:44:29
我正在嘗試使用 SciPy 和 PyGame在我隨機(jī)生成的世界地圖上創(chuàng)建和顯示Voronoi 圖。我遇到的問題是,總有一個點有奇怪的線條,它們會忽略其他任何東西,并像星星或其他東西一樣散布在地圖上。從左上角和左下角可以看出,它們不會無限遠(yuǎn)。我怎樣才能擺脫它?顯示內(nèi)容:我的代碼:import numpyimport randomimport pygamefrom scipy.spatial import Voronoidef __generate_voronoi():    """    Randomly chooses various points within the x and y dimensions of the map.    Then, uses SciPy to generate a voronoi diagram with them, and returns it.    :return: SciPy voronoi diagram    """    point_arr = numpy.zeros([900, 2], numpy.uint16)    for i in range(900):        point_arr[i][0] = numpy.uint16(random.randint(0, 1600))        point_arr[i][1] = numpy.uint16(random.randint(0, 900))    return Voronoi(point_arr)def draw_voronoi(pygame_surface):    # generate voronoi diagram    vor = __generate_voronoi()    # draw all the edges    for indx_pair in vor.ridge_vertices:        start_pos = vor.vertices[indx_pair[0]]        end_pos = vor.vertices[indx_pair[1]]        pygame.draw.line(pygame_surface, (0, 0, 0), start_pos, end_pos)
查看完整描述

1 回答

?
慕標(biāo)琳琳

TA貢獻(xiàn)1830條經(jīng)驗 獲得超9個贊

感謝這里的耐心評論者,我了解到vor.vertices對于無限大的點的第一個索引將返回 -1。這會產(chǎn)生一個問題,因為 python 將 -1 視為列表或數(shù)組最后一個元素的索引。


我的問題的解決方案不是從vor.vertices.


我通過用draw_voronoi()以下代碼替換函數(shù)來實現(xiàn):


def draw_voronoi(pygame_surface):


    # generate voronoi diagram

    vor = __generate_voronoi()


    # draw all the edges

    for indx_pair in vor.ridge_vertices:


        if -1 not in indx_pair:


            start_pos = vor.vertices[indx_pair[0]]

            end_pos = vor.vertices[indx_pair[1]]


            pygame.draw.line(pygame_surface, (0, 0, 0), start_pos, end_pos)

這產(chǎn)生了這個圖像:

http://img1.sycdn.imooc.com//61b16dd70001e0d706550382.jpg

查看完整回答
反對 回復(fù) 2021-12-09
  • 1 回答
  • 0 關(guān)注
  • 201 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號