Jump to content
Julien BOLBACH

Nearpoint question

Recommended Posts

Hi guys,

I'm trying to do the following on a geometry of points :

- find the closest point to the first one, then iterate through this newly find point and find the closest one, etc.

I'm trying to use nearpoint for that, by using the ptgroup. I create a group with all the points at the beginning, and through my loop, I remove the points found on this group.

But it doesn't work, and I'm not sure what I'm doing right ...

int neworder[] = {};

// start with point 0
int npt = 0;
push(neworder,npt);

// remove point from group
setpointgroup(0,"points",npt,0);

for(int i=0;i<10;i++){
    vector p = point(0,"P",npt);
    // find nearest point from points group                   
    npt = nearpoint(0,"points",p);
    
    // remove newly point from group                   
    setpointgroup(0,"points",npt,0);
                       
    push(neworder,npt);
    }
    
i[]@points = neworder;

I'm doing this on a wrangle node at the detail level (so only once).

Any idea what I'm doing wrong ?

Thanks,

 

Julien

Share this post


Link to post
Share on other sites

Maybe better to use "findshortestpath"?

Share this post


Link to post
Share on other sites

Hallo Julien

I think you're current set up would return the same point every time it resulting in a array of 0's
This is caused by the nearpoint function. This returns the first point it find near the provided coordinates with should be point 0.
In addition you say to find the nearest point  in the provided point group that only contains point 0.

The following code should do what you wan't.

int points_visited[]; 	// A list of points already visited
int curr_point = 0;		// current point to look from
int max_distance = 100;	// maximum search distance
int max_points = 10;	// max number of points to find
vector P = point(0, "P", curr_point);	//Stores the position of the points where looking from
int handle;	// variable for the point cloud

for(int i = 0; i < 10; i++){
    handle = pcopen(0, "P", P, max_distance, max_points);	// Create a new point cloud containing all points in order from closest to farthest
    while(pciterate(handle)){	// Iterate over the point cloud
        pcimport(handle, "P", P);	// Load new Position
        pcimport(handle, "point.number", curr_point);	// Get point number
        if(find(points_visited, curr_point) < 0){	// See if point number is already in the visited array
            append(points_visited, curr_point);	//if not add point to array
            pcclose(handle);	// Close the PC 
            break;	// Stop the while loop
        }
    }
}
printf("%d\n", points_visited);

 

Share this post


Link to post
Share on other sites

Thanks !

 

I thought removing the point from the group would do the trick, but apparently it didn't ...

Thanks again, its works well !

 

Julien

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×