Jump to content
Sign in to follow this  
domsewell

Issue performing if statement on an array

Recommended Posts

Hi guys,

 

Im a little stumped on a vex issue im having whilst trying to utilize the nearpoints function when building an array.

The idea is that i have multiple curves, each with different colour values,  which i group the end points of and then run a function which gathers all the nearest points to each of these endpoints and assigns them to an array. (this is currently working as can be seen in my spreadsheet.)

However, i then wish to take this array that has been created for each of the endpoints and run an if statement through it that says if the points in the array have a different colour value to the end point they belong to then add them to a group.

Im then hoping to perform a nearpoint function using this group as a filter to get the nearest point that belongs to any curve other than itself.

Im unfortunately having an issue with this if statement as it seems to only output points 0-9 regardless of the previous rules set in the code.

 

Help is really appreciated as im truly stumped on this one.

 

Thanks in advance guys!

Current Code.png

spreadsheet.png

Nearest_Points_Array_Problem.hip

Share this post


Link to post
Share on other sites

I wonder if VEX is failing on the setpointgroup, because you have two different styles of quotes? Try double quoting set.

Share this post


Link to post
Share on other sites

@Atom sadly that doesn't seem to have changed my result at all. if you are able to take a look at the project file id much appreciate it.
 

Cheers,

Dom

Share this post


Link to post
Share on other sites

I have found that the exact comparison between two float values in Houdini can sometimes fail. Try revising your detection IF statement to be more of a threshold, or close to the mark type of detection.

float threshold = 0.04;	//ch("threshold") or add slider.
if(abs(APC-@Cd.x) > threshold ) {
	//Different.
} else {
	// Close enough.
}

 

Edited by Atom

Share this post


Link to post
Share on other sites

Hi @Atom Thank you so much for looking in to this for me i was aware that float precision may have been an issue, this didn't seem to be the fix however.

The good news is that the code now works as intended by switching out the for each loop for a regular for loop

 

5d72606d4e6dc_workingcode.thumb.png.057f7a784566f0bf3bd6744893c52e1d.png

 

Thanks again i appreciate it!

  • Like 1

Share this post


Link to post
Share on other sites
On 9/4/2019 at 11:45 AM, domsewell said:

Im unfortunately having an issue with this if statement as it seems to only output points 0-9 regardless of the previous rules set in the code.

8 minutes ago, domsewell said:

The good news is that the code now works as intended by switching out the for each loop for a regular for loop

its because with foreach loop, num already contained point number and not index, so when you used nPs[num] in your setpointgroup(), it was only going to return something for points 0-9 as your nPs was max 10 points, so in your original code you can try using num directly

 

  • Like 2

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
Sign in to follow this  

×