在MATLAB中对顺时针多边形点进行排序 [英] Sorting clockwise polygon points in MATLAB

查看:53
本文介绍了在MATLAB中对顺时针多边形点进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个向量,它们是多边形 8 个顶点的 x 和 y 坐标

I have 2 vectors that are x and y coordinates of the 8 vertexes of a polygon

x=[5 5 7 7 9 9 5 7]

x=[5 5 7 7 9 9 5 7]

y=[8 6 6 8 6 8 10 10]

y=[8 6 6 8 6 8 10 10]

我想对它们进行排序(顺时针)以获得正确的向量(正确绘制多边形)

I wanna sort them (clockwise) to obtain the right vectors (to draw the polygon correctly)

x=[5 7 9 9 7 7 5 5]

x=[5 7 9 9 7 7 5 5]

y=[6 6 6 8 8 10 10 8]

y=[6 6 6 8 8 10 10 8]

推荐答案

第一步:求顶点的未加权均值:

Step 1: Find the unweighted mean of the vertices:

cx = mean(x);
cy = mean(y);

第 2 步:求角度:

a = atan2(y - cy, x - cx);

第 3 步:找到正确的排序顺序:

Step 3: Find the correct sorted order:

[~, order] = sort(a);

第 4 步:重新排列坐标:

Step 4: Reorder the coordinates:

x = x(order);
y = y(order);

这篇关于在MATLAB中对顺时针多边形点进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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