# Group particles into four parts

## Recommended Posts

Hi,

I am sorry if this is a silly question, I want to group N number of points into 4 seperate groups, suppose 30% =group1, 20% = group2, 10% = group 3, 40% = group 4. In such a way that no particle is common in any of the groups so that I can use those groups to use popwind to effect them seperately and color them seperately. Please Help.

Thanks.

##### Share on other sites

You could put the following code into a POP Wrangle to separate your particles into 4 groups.

```if (@id % 10 < 3){
@group_group1 = 1;
}

if (@id % 10 >= 3 && @id % 10 < 5){
@group_group2 = 1;
}

if (@id % 10 >= 5 && @id % 10 < 6){
@group_group3 = 1;
}

if (@id % 10 >= 6){
@group_group4 = 1;
}```

And then you could also replace @id by rand(@id+123) * 10 to get a random seed

• 1

##### Share on other sites
10 minutes ago, celd said:

You could put the following code into a POP Wrangle to separate your particles into 4 groups.

```
if (@id % 10 < 3){
@group_group1 = 1;
}

if (@id % 10 >= 3 && @id % 10 < 5){
@group_group2 = 1;
}

if (@id % 10 >= 5 && @id % 10 < 6){
@group_group3 = 1;
}

if (@id % 10 >= 6){
@group_group4 = 1;
}```

And then you could also replace @id by rand(@id+123) * 10 to get a random seed

Wowww!! This works perfectly. Thank you so mucccch. Please could you also explain this code a bit. Like :

```if (@id % 10 < 3){
@group_group1 = 1;
}

if (@id % 10 >= 3 && @id % 10 < 5){
@group_group2 = 1;
}```

Please explain the above part , suppose I have a 100 points. can you please explain the above part to me?

##### Share on other sites
`if (@id % 10 < 3)`

This divides the id number by 10 and then checks if the value after decimal point is below 3 (modulo operation), if it is, it assigns the particle into a given group.

So in practice it will do for example: 1/10 = 0.1, then it takes the 1 and compares if 1<3 and then assigns the group; or 98/10 = 9.8 where 8<3 - no group assignment.

`if (@id % 10 >= 3 && @id % 10 < 5)`

This does the same thing except it compares with 2 different values and returns true if both statements are correct, resulting in grouping two tenths of your points.

## Create an account

Register a new account