Jump to content

Issue performing if statement on an array


domsewell

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

Link to comment
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
Link to comment
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
Link to comment
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
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...