在MATLAB中顺时针排列多边形点

编程入门 行业动态 更新时间:2024-10-16 22:21:27
本文介绍了在MATLAB中顺时针排列多边形点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

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

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

y = [6 6 6 8 8 10 10 8] 第1步:找到质心:

cx => (x)的均值; cy = mean(y);

第二步:找到角度:

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

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

[〜,order] = sort(a);

第4步:重新排序坐标:

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

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]

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]

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

解决方案

Step 1: Find the centroid:

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

Step 2: Find the angles:

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

Step 3: Find the correct sorted order:

[~, order] = sort(a);

Step 4: Reorder the coordinates:

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

更多推荐

在MATLAB中顺时针排列多边形点

本文发布于:2023-11-29 20:55:59,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多边形   排列   顺时针   MATLAB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!