Jump to content

If statements on items in an array

Recommended Posts

This is my first time diving into arrays.

I'm using the pccone function to search for points in a particular direction, then colour them red.

This is working fine until I bring an if statement into play.. I'm asking if the points in the array are white, then change their colour to red. This seems to change all white points to red, not just the ones in the array.

I don't think I'm understanding arrays, or possibly even if statements correctly.

File attached


Link to comment
Share on other sites

Try something like this.

int x[] = pccone(0, "P", {0,0,0}, {0,1,0}, 0.25, 1, 1000);

foreach(int point; x){
    vector candidate_Cd = point(0,"Cd", point);
    if(candidate_Cd=={1,1,1}) setpointattrib(0, "Cd", point, {1,0,0});



Link to comment
Share on other sites

@LibrarianThanks for the heads up on Fe-Elf, there looks to be a lot of handy tools in there! I'll take a bigger dive into this sometime soon.

@Atom Thank you so much for this example, it's helping me better understand what's going on here. Probably just because I'm new to this, but it seems strange to first declare a new vector attribute called 'candidate_Cd' rather than using Cd that is already on those points. Is that what's going on here?

Anyhow, this is working for me. Cheers for the help!

  • Like 1
Link to comment
Share on other sites

It's because pccone returns a list of point numbers. Those points contain the Cd value you want to evaluate, not the point you are running over. Remember, you're evaluating that loop for every single point, which might be a little redundant.

Edited by Atom
Link to comment
Share on other sites

@Atom Hmmm, maybe I'm not doing this the most efficient way then. I'll explain what I've been trying to do:

I'm wanting to search only upwards and to detect if the point above is white - and if so, change its colour to red.
I was using the pccone formula, as I thought this was the only way to search in a specific direction, rather than something like pcfind which searches out in all directions.

Or, were you saying it is not the best idea to run this over every single point, as it will end up being pretty slow?

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.

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...