沿多边形边界但沿CW/CCW生成等距点 [英] Generating equidistance points along the boundary of a polygon but CW/CCW

查看:75
本文介绍了沿多边形边界但沿CW/CCW生成等距点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个多边形的顶点,并且它们都面向CCW.我希望沿着该多边形的边界生成 n 个等距点.有谁知道这样做的任何现有软件包,如果没有,一个人可以使用一种算法?我正在用Python工作.例如,如果要讨论的多边形是矩形,这就是我想要的:

Suppose I have the vertices of a polygon and they are all oriented CCW. I wish to generate n equidistance points along the boundary of this polygon. Does anyone know of any existing package that does this, and if not, an algorithm one can use? I am working in Python. For example, here is what I would like if the polygon in question is a rectangle:

enter image description here

解决方案

shapely:

import shapely.geometry as sg
import shapely.affinity as sa
import matplotlib.pyplot as P
import numpy as np

n = 7
k = 11
ori = sg.Point([0,0])
p = [sg.Point([0,1])]
for j in range(1,n):
    p.append(sa.rotate(p[-1],360/n,origin=ori))
ngon = sg.Polygon(p)
P.figure()
P.plot(*ngon.exterior.xy,"-k")
P.scatter(*np.transpose([ngon.exterior.interpolate(t).xy for t in np.linspace(
    0,ngon.length,k,False)])[0])
P.axis("equal");P.box("off");P.axis("off")
P.show(block=0)

这篇关于沿多边形边界但沿CW/CCW生成等距点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆