# Creating a Subway network in VEX

## Recommended Posts

I am trying to create a subway network with VEX.

In order to define individual end stations I assigned all points to sectors according to their radial position. Now I am looking for a way to find the bluest/greenest point for each sector.

i@result shows me the best match for all the points, but how can I loop through groups (i.e. "sector_0", "sector_1" and so on) and put all matching points into one array?

vector seek_clr = {0,1,1};

//Finds points with a similar color
int pcloud = pcopen(0, "P", @P, 0.4, 6);
int closecolor[] = pcfind(0, "sector_0", "Cd", seek_clr, 2, 5);
i@result_0 = closecolor[1];

Edited by konstantin magnus

##### Share on other sites
1 hour ago, Shinjipierre said:

I am not looking for a pathfinding solution. I basically want to split up a pointcloud function in areas.

Edited by konstantin magnus

##### Share on other sites

you could sort your points by their polar angle and range them for exemple 300-330 is blue

"converting between polar and cartesian coordinates"
https://en.wikipedia.org/wiki/Polar_coordinate_system

Edited by deniz

##### Share on other sites

please look at the file first. the whole thing is already done with polar coords. and maybe read my post:

3 hours ago, konstantin magnus said:

I am looking for a way to find the bluest/greenest point for each sector

Edited by konstantin magnus

##### Share on other sites

i am sorry i answered in affect when i saw the picture, but "seek" is not defined,

int extreme[] = pcfind(0, "Cd", seek, 2, 1);  is maybe what you are looking for

Edited by deniz

##### Share on other sites
2 hours ago, deniz said:

maybe what you are looking for

No, thats not it. I think I just need to know how to use point clouds inside for loops or maybe rather for loops inside point clouds.

Edited by konstantin magnus

##### Share on other sites
22 minutes ago, konstantin magnus said:

No, thats not it. I think I just need to know how to use point clouds inside for loops.

i dont get it why you are using closestpoint,

you want to find the bluest/greenest color value for each sector and store the bluest/greenest from each sector to a list right ?

##### Share on other sites

colors and positions are interchangeable I hope. thats why pcfind should also be able to look for colors in points.

Maybe I have to

• iterate through point groups
• use separate arrays for each sector
• to finally assign the first entries of each array to one big array

Or is there an easier solution?

Edited by konstantin magnus

##### Share on other sites

I found a solution:

vector seek_clr = {0,1,1};
int sectors = detail(0, "sectors", 0);
i[]@result[sectors];

int pcloud = pcopen(0, "P", @P, 0.4, 6);
for(int i = 0; i < sectors; i++) {
string group = s[]@groups[i];
int closecolor[] = pcfind(0, group, "Cd", seek_clr, 2, 5);
if(closecolor[1] == @ptnum) setpointgroup(0, "in", @ptnum, 1, "set");
@result[i] = closecolor[1];
}

Edited by konstantin magnus

##### Share on other sites

for something like this it´s most probably faster to just interate over the points instead of using pcfind. when you rely on pointcloud functions houdini needs to build a kdtree and in your case it has to rebuild the tree for every "sector". since accessing the tree is fast but building it is relatively slow you loose the advantage of using pointclouds.  this becomes even more apparant when you have a high number of "sectors".
anyway, both versions are attached ...

hth.
petz

Edited by petz
• 2

##### Share on other sites

thank you! i will try to get this..