modulus function

   22576   7   3
User Avatar
Member
18 posts
Joined: Nov. 2012
Offline
Hey everybody, Does anyone could give me an example of the modulus function in expression? since i very confused about this function.
Thanks.
User Avatar
Member
4516 posts
Joined: Feb. 2012
Offline
Hi,

You can use:

5 % 2

to get the remainder 1.

More info here:
http://www.cprogramming.com/tutorial/modulus.html [cprogramming.com]
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
18 posts
Joined: Nov. 2012
Offline
Thanks, but, how this information could be useful in houdini?

Best.
User Avatar
Member
205 posts
Joined: Dec. 2009
Offline
You can use it for cycling numbers.
E.g. in a file sop: $HIP/model_`$F%30`.bgeo

Or to simulate a continuous movement of a repeating geometry.
Put in a grid sop's transformZ channel something like ($FF/20)%1

For sure, there's much more use for it…
User Avatar
Member
18 posts
Joined: Nov. 2012
Offline
thank you very much
User Avatar
Member
54 posts
Joined: Dec. 2011
Offline
I use it to group a random selection of many objects fairly often
User Avatar
Member
205 posts
Joined: Dec. 2009
Offline
A bit confusing is the use of the word modulus in (british?) english. The absolute value function abs() is often called modulus.

see here (first paragraph) – abs() in Houdini
http://en.wikipedia.org/wiki/Absolute_value [en.wikipedia.org]

vs. here – % in Houdini
http://en.wikipedia.org/wiki/Modular_arithmetic [en.wikipedia.org]
User Avatar
Staff
2540 posts
Joined: July 2005
Offline
Modulus is used to create “sawtooth” channels from varying data (channels, attributes, sequences of images/geometry, etc).

For example you can take some geometry with the same number of points per row and create values for each point like:

$PT%100

where 100 is the number of points per row and would return 0-99 for each row in your geometry. Comes in handy for a very lightweight way to set increasing attributes on curves for fur/hair/grass that have the same number of points per curve where you don't have access to the SOP network or geometry loaded in from disk.

—-

Modulus is used in crowds all the time. Either for cutting up a path in to strides and then index in to the right motion geometry or channels.


Countless other uses where you can identify a repeating pattern and you wish to work with it.

Attachments:
modulus_on_points.hip (78.4 KB)

There's at least one school like the old school!
  • Quick Links