Deeper meaning behind fit function

   3108   5   0
User Avatar
Member
161 posts
Joined: Nov. 2018
Offline
So i was thinking, as a beginner in learning Houdini, just what is the purpose of fit function?
I mean, i understand it as a ‘'clamp’' function, but why would anyone in the first place use a clamp?
Is it not simpler just to re-write the values (or keyframes) to different values? It's the same a using a clamp = fit?

For some example, don't know, maybe if i set an object to move from 5 to 10 in x direction, instead of using an fit function, can't i just change the animation within few clicks to do the same thing? Or is it a bad example?
Can anyone stick with me to clarify to me this purpose of function?

Happy to learn.
User Avatar
Member
2164 posts
Joined: Sept. 2015
Offline
Well, there is no specific application with the fit function. It could be looked at as a utilitarian function.

I use it many times in different contexts ( many times in conjunction with ramp parameters ). Until that time comes for your unique application that requires it because there are no other ways you can think of to use it, you won't ‘appreciate it’.

I don't have time now…but keep watch on this thread…I'm sure someone will be able to give you an example in a hip or explain their application.
User Avatar
Member
504 posts
Joined: July 2005
Offline
Hi,

fit() and clamp() are a bit different.
Since clamp() defines min/max boundaries for your values, fit() tranforms the values from one interval into another with respect to their relative position of their interval. For example: If you have the value 0.4 in the (0,1) interval the fit() function will map it to 70 in the (50, 100) interval.
As BabaJ already mentioned, these functions are auxiliary functions, which are usually applied on values, which has to be passed into other functions (like ramps), which expects a specific intput, or it can be used as an output modifier aswell.
Here is a simple example, where both function are applied on the y-value of an input geometry.

Attachments:
fit_clamp_example.hipnc (239.8 KB)

User Avatar
Member
8177 posts
Joined: Sept. 2011
Offline
fit is sometimes used directly for animation, such as
fit($FF, 1001, 1030, 0, 180)
in a y rotate channel, as it allows one to describe and conceptualtize the entirety of an animation at one glance. With keyframes, there must be a deferral to a spreadsheet or graph to see how the plot changes over time. With a function such as fit, you can tell what an animation will do for all time just by reading the numbers. (it's technically possible to use keyframes to change the function to a different one at a different time, but that is besides my point)

Yes you can create a simple two key animation in a few clicks, but you can create a fit function in zero clicks.
User Avatar
Member
161 posts
Joined: Nov. 2018
Offline
Aizatulin
Hi,

fit() and clamp() are a bit different.
Since clamp() defines min/max boundaries for your values, fit() tranforms the values from one interval into another with respect to their relative position of their interval. For example: If you have the value 0.4 in the (0,1) interval the fit() function will map it to 70 in the (50, 100) interval.
As BabaJ already mentioned, these functions are auxiliary functions, which are usually applied on values, which has to be passed into other functions (like ramps), which expects a specific intput, or it can be used as an output modifier aswell.
Here is a simple example, where both function are applied on the y-value of an input geometry.


Thanks for the explanation, i do believe i understand it, but when i opened your file in clamp and fit functions i saw the following expressions;

for fit @P.y = fit(@P.y, chf('src_a'), chf('src_b'), chf('tgt_a'), chf('tgt_b'));
for clamp @P.y = clamp(@P.y, chf('min'), chf('max'));

I was expecting to see numeric values since the fit and clamp work on, but i see chf,src(a,b),tgt(a,b)…i mean, i don't quite understand what does it reference, and where are those references that they point to.
I was expecting someting from the manual, like: fit01(3, 6) something like tha… Could you elaborate the expressions with the ‘'to dummy’' aproach , or anyone else. It's the first time i encounter the expressions as a learner in the near starting phase.

Edit: Based on what did you set min and max values? I don't see any values that you command through that.
Edited by MilanB - Sept. 17, 2019 17:52:12
User Avatar
Member
504 posts
Joined: July 2005
Offline
chf('xyz') is a reference to a float field for user inputs. If the field doesn't exist, you can always click the white button on the right side of the VEXpression input editor (near the drop down menu).

Attachments:
chf_pic.jpg (19.9 KB)

  • Quick Links