jason candelora

Greenhorn

Posts: 16

posted 13 years ago

Hello,

I have an array that contains Points that are found on an X-Y axes. I am trying to sort these Points by their closeness to one another. In theory, I need to take the first point in my array, add it to the new array. Then take the second point in my array and insert it into the second place in the new array..heres where the fun starts...I then take the third point of my first array and check to see how far it is from the each of the 2 points in my new array, then it gets inserted into the new array directly after the point to which it is closest. Then we go to the fourth point and compare its distance from each of the 3 points in my new sorted array and insert it after the point that it is closest and so on until I run out of points...I am completely lost on this one...I am not looking for someone to feed me a ton of code that I can just plug in and go, I would like for someone to just point me in the right direction so I can at least get started...

Thanks for your time!!

Jason

I have an array that contains Points that are found on an X-Y axes. I am trying to sort these Points by their closeness to one another. In theory, I need to take the first point in my array, add it to the new array. Then take the second point in my array and insert it into the second place in the new array..heres where the fun starts...I then take the third point of my first array and check to see how far it is from the each of the 2 points in my new array, then it gets inserted into the new array directly after the point to which it is closest. Then we go to the fourth point and compare its distance from each of the 3 points in my new sorted array and insert it after the point that it is closest and so on until I run out of points...I am completely lost on this one...I am not looking for someone to feed me a ton of code that I can just plug in and go, I would like for someone to just point me in the right direction so I can at least get started...

Thanks for your time!!

Jason

Elouise Kivineva

Ranch Hand

Posts: 154

Ravi Srinivas

Greenhorn

Posts: 26

posted 13 years ago

Hi,

Here's some pseudocode I've come up with, hope it's correct..

When inserting into the array, you'll have to shift all elements after the insertion point by one step to the right. You could use vector instead of array to make insertion easier.

I'm assuming that the minimum distance between points will always be less than 999999 (or some such similiar huge number).

If the new point is equally "least distant" from several other points, it will be placed right after the first such point.

Ravi

[ March 12, 2004: Message edited by: Ravi Srinivas ]

[ March 12, 2004: Message edited by: Ravi Srinivas ]

Here's some pseudocode I've come up with, hope it's correct..

When inserting into the array, you'll have to shift all elements after the insertion point by one step to the right. You could use vector instead of array to make insertion easier.

I'm assuming that the minimum distance between points will always be less than 999999 (or some such similiar huge number).

If the new point is equally "least distant" from several other points, it will be placed right after the first such point.

Ravi

[ March 12, 2004: Message edited by: Ravi Srinivas ]

[ March 12, 2004: Message edited by: Ravi Srinivas ]