SamuZai
DavidKahlVFX
DavidKahlVFX

patreon


Quick Tip #4 - Ways to find the highest Point

I found it was a fun thing to offer you some examples to solve a given problem and you chip in with your own solutions. So let's do that more often and call it "The Quick Tip Challenge" ;-)

Disclaimer - for every option that uses VEX you can of course create the VOP that does the exact same. So if you create another option keep in mind that if using a VOP the general approach should be a bit different.

So this time I want to find the highest point of a given geometry. I build a test framework for that to make it easy to visualize.

We have a rotated box and an integer attribute called highest on each point. If that attribute holds a 1, this point is the highest and gets painted red. So we need to figure out how to set the correct point to 1. 

Just for demonstration - it's fairly easy to see that point 7 is the highest. So the Mr. Obvious solution could be to just set the attribute for the point we can make out with our own eyes.

But that doesn't count. So here are my 5 ways of finding the highest Point. 

Why find the highest point you ask - because reasons!

Option 1 - Brute Force

This is painfully stupid but as a VEX guy I feel the need to give you the so called brute force approach. 

It's like when you try to run a marathon with your shoelaces knotted together. You are going to get there eventually.

I loop over each point and save the position. Then I compare that saved position with the next one and always when the new position is higher it becomes the new highest position. 

I also have to drag the point number of that value with me and use that point to set the highest attribute to 1.

Option 2 - The sorted One

This is probably one of the better approaches. There are many problems that can be solved if you know exactly how the points are numbered. The sort node is a very versatile tool in that regard. 

For this simple task sort by Y and reverse the order. By doing so the highest point has number 0.

Option 3 - The Promoter

Promoting attributes with a specific method is very useful to find averaged values but also min and max values. So by saving the Y component of the position as a single float attribute we can use attribute promote to create a new detail attribute with the max of those values.

Then compare that value (the highest Y position) with the points and you will end up with the highest pointnumber.

Option 4 - Bound to a Box

Now it gets a bit abstract. The problem at hand - finding the highest point is a bit too simple to go this route BUT it's still a valid tool you might find useful for the real problems you encounter in your projects.

With getbbox_max() you get a vector holding the max values of the bounding box. After putting that vector into an attribute (or just save only the Y component as float) you can again compare that to your points. The highest point will match that box. 

Option 5 - Everything is Relative

This is very similar to the previous option but it is a bit more elegant. I also like this option the most since it is done with one wrangle and fairly simple code.

The relbox function creates a new vector that provides you with a value from 0 to 1 giving you the relative position of the point compared to the bounding box. So if the point is touching the bounding box it has a 1 for that component and if it's in the center of the geometry it's 0.

Fo our task that means if the relbbox vector has a 1 in the Y component - that's the highest point. 


So do you have more ideas? And if not what would be your choice?

Cheers 

Dave


More Creators