排序X和Y顶点的数组? iOS/目标C [英] Sorting an Array of X and Y Vertice Points ? iOS / Objective C

查看:110
本文介绍了排序X和Y顶点的数组? iOS/目标C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个称为Line的Core Data实体.每行包含一个VerticePoint实例,该实例包含一个x和y属性.这些x和y顶点形成简单的2D多边形.

I have a Core Data entity called Line. Each line contains an instance of a VerticePoint which contains an x and y property. These x and y vertices form simple 2D polygons.

我想做的是对这些Line对象的数组进行排序,这些数组以随机顺序排列,以使形状的原点(左下角)始终是数组中的第一个元素,然后是其余的顶点从原点沿逆时针方向.

What I want to do is sort an array of these Line objects which is in random order so that the origin of the shape, the bottom left point, is always the first element in the array, then followed by the remaining vertices wound in counter-clockwise direction from the origin.

所以说我原始数组中的点是(x y轴的中心为0,0):

So say the points in my original array are (x y axis is centred at 0,0) :

x = 20, y = 20
x = 20 , y= 10
x = 10, y=10
x = 10, y =20
x = 15, y = 10

我想对它们进行排序:

x = 10, y=10
x = 15, y = 10
x = 20 , y= 10
x = 20, y = 20
x = 10, y =20

非常感谢

推荐答案

您可以使用

- (NSArray *)sortedArrayUsingDescriptors:(NSArray *)sortDescriptors

NSArray的

.

of NSArray.

您可以使用多个描述符.只需初始化两个描述符,一个使用x初始化,一个使用y属性.

You can use more then one descriptor. Just initialize two descriptors one with x, one with y property.

这篇关于排序X和Y顶点的数组? iOS/目标C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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