有谁知道如何排序3个数组? [英] Anyone know how to sort 3 arrays?

查看:136
本文介绍了有谁知道如何排序3个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我有3个双精度数组,代表3D坐标。阵列是8000点,所以我在这里举了一个例子。


x = {0.3,0.6,0.2} y = {2.0,0.3,0.2} z = {1.0,2.0, 3.0}


所以x(0),y(0),z(0)是3D点x(1),y(1),z(1)是另一个3D点等等。我想要做的是从最接近的(0,0,0)对空间中的3D点进行排序,因此3个数组同时排序,但保持x(i),y(i),z( i)是3D点。我已经看到它可以使用array.sort(x,y)为2个数组制作,其中x被排序,y在x索引之后重新定位。

这可以为3个数组完成?

(希望我已经解释过了自己:P)非常感谢。

Hi everyone. I have 3 arrays of doubles that represent 3D coordinates. The arrays are of 8000 points so I put here a little example.

x = { 0.3 , 0.6 , 0.2} y = {2.0 , 0.3 , 0.2} z = {1.0 , 2.0 , 3.0}

So x(0),y(0),z(0) is a 3D point x(1),y(1),z(1) is another 3D point and so on. What I would like to do is to sort the 3D points in space from the closest to (0,0,0), so the 3 arrays are simultaneously sorted but maintaining the fact that x(i),y(i),z(i) is a 3D point. I''ve seen that it can be made for 2 arrays using array.sort(x,y) where x is sorted and y is recolocated following x index.
Can this be done for the 3 arrays?
(Hope I''ve explained myself :P ) Many thanks.

推荐答案

$ b $大家好。我有3个双精度数组,代表3D坐标。阵列是8000点,所以我在这里举了一个例子。


x = {0.3,0.6,0.2} y = {2.0,0.3,0.2} z = {1.0,2.0, 3.0}


所以x(0),y(0),z(0)是3D点x(1),y(1),z(1)是另一个3D点等等。我想要做的是从最接近的(0,0,0)对空间中的3D点进行排序,因此3个数组同时排序,但保持x(i),y(i),z( i)是3D点。我已经看到它可以使用array.sort(x,y)为2个数组制作,其中x被排序,y在x索引之后重新定位。

这可以为3个数组完成?

(希望我已经解释过了自己:P)非常感谢。
Hi everyone. I have 3 arrays of doubles that represent 3D coordinates. The arrays are of 8000 points so I put here a little example.

x = { 0.3 , 0.6 , 0.2} y = {2.0 , 0.3 , 0.2} z = {1.0 , 2.0 , 3.0}

So x(0),y(0),z(0) is a 3D point x(1),y(1),z(1) is another 3D point and so on. What I would like to do is to sort the 3D points in space from the closest to (0,0,0), so the 3 arrays are simultaneously sorted but maintaining the fact that x(i),y(i),z(i) is a 3D point. I''ve seen that it can be made for 2 arrays using array.sort(x,y) where x is sorted and y is recolocated following x index.
Can this be done for the 3 arrays?
(Hope I''ve explained myself :P ) Many thanks.



我不这么认为

I don''t think so


我做到了。只是一些思考和一些辅助数组,尽管有很多内存使用,这里是代码:

Well I''ve done it. Just a bit of thinking and some auxiliar arrays, albeit lot of memory usage, here''s the code:

展开 | 选择 | 换行 | 行号


似乎最简单的方法是将数组组合成一个用户定义类型的单个数组。换句话说,就像......

Seems as though the simplest thing would be to combine the arrays into a single array of user-defined type. In other words, something like...

展开 | 选择 | Wrap | 行号


这篇关于有谁知道如何排序3个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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