Jump to content

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

Link to comment
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);

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...