日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python二维列表排序_使用Python按顺时针方向排序二维坐标列表?

發布時間:2023/12/3 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python二维列表排序_使用Python按顺时针方向排序二维坐标列表? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這應該說明問題,給出一個可視化工具

但對于在同一距離上獲得一組點的正確入口點來說,這并不總是有效的import random

import pylab

import cmath

from itertools import groupby

pts = [(random.randrange(-5,5), random.randrange(-5,5)) for _ in range(10)]

# for this problem complex numbers are just too good to pass up

z_pts = [ i[0] + 1j*i[1] for i in pts if i != (0, 0)]

z_pts.sort(key = lambda x: abs(x))

gpts = [[*g] for _, g in groupby(z_pts, key = lambda x: abs(x) ) ]

print(*gpts, sep='\n')

spts = [1j/2]

for e in gpts:

if len(e) > 1:

se = sorted(e, key = lambda x: cmath.phase(-x / spts[-1]))

spts += se

else:

spts += e

print(spts)

def XsYs(zs):

xs = [z.real for z in zs]

ys = [z.imag for z in zs]

return xs, ys

def SpiralSeg(a, b):

'''

construct a clockwise spiral segment connecting

ordered points a, b specified as complex numbers

Inputs

a, b complex numbers

Output

list of complex numbers

'''

seg = [a]

if a == 0 or a == b:

return seg

# rotation interpolation with complex numbers!

rot = ( b / a ) ** ( 1 / 30 )

# impose cw rotation direction constraint

if cmath.phase( b / a ) > 0: # add a halfway point to force long way around

plr = cmath.polar( b / a )

plr = (plr[0]**(1/2), plr[1] / 2 - 1 * cmath.pi ) # the rotor/2

a_b = cmath.rect(*plr) * a # rotate the start point halfway round

return SpiralSeg(a, a_b) + (SpiralSeg(a_b, b))

for _ in range(30):

a *= rot

seg.append(a)

return seg

segs = [SpiralSeg(a, b) for a, b in zip(spts, spts[1:])]

pylab.axes().set_aspect('equal', 'datalim')

pylab.scatter(*XsYs(z_pts))

for seg in segs:

pylab.plot(*XsYs(seg))

[(1-2j), (-2-1j)]

[(2-3j)]

[(1+4j)]

[(3+3j)]

[(-3-4j), (3-4j), (4-3j)]

[(1-5j)]

[(-4-4j)]

[0.5j, (-2-1j), (1-2j), (2-3j), (1+4j), (3+3j), (-3-4j), (3-4j), (4-3j), (1-5j), (-4-4j)]

[-1j]

[(-1-1j)]

[(-1-2j), (-1+2j), (2+1j)]

[(-4+0j)]

[(1-4j)]

[-5j, (-4-3j)]

[(1-5j)]

[0.5j, -1j, (-1-1j), (-1-2j), (2+1j), (-1+2j), (-4+0j), (1-4j), (-4-3j), -5j, (1-5j)]

總結

以上是生活随笔為你收集整理的python二维列表排序_使用Python按顺时针方向排序二维坐标列表?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。