PDA

View Full Version : comparing something, with a tolerance?


Leffler
06-03-2009, 02:13 PM
Hi!

I want to compare some values, but I seem to have some weird "accounting-errors". The values are equal for the first 6 decimals, then something weird happens

Like this

What is Sel: L_shldr_Stretch_mdNode
What is inp1 : 7.41289711
What is inp2 : 7.41289711

What is Sel: R_shldr_Stretch_mdNode
What is inp1 : 7.412885666
What is inp2 : 7.412888527

So if i compare if inp1 is the same value as inp2, it will give me false

Is it possible to sort of "cut away" those last decimals?

Thanks,

Otto

JoshM
06-03-2009, 02:29 PM
You should be able to use the MEL command 'equivalent' in conjunction with the 'tolerance' command.

HTH,
Josh

Leffler
06-03-2009, 02:31 PM
yes, that what I came up with. Was a bit fast to ask, just needed a cup of coffee to find an answer :)

//get the values to compare them
float $getInput1X_value = `getAttr ($sel[$x] + ".input1X")`;
float $getInput2X_value = `getAttr ($sel[$x] + ".input2X")`;

$equals = equivalentTol($getInput1X_value,$getInput2X_value, 0.01);

if($equals == 1 )

dealer2couleurs
06-03-2009, 07:25 PM
to compare with a tolerance, you can compare the difference...

for exemple you want to compare X and Y
you need to compare X-Y with your tolerance

if( abs(X-Y) < abs(tolerance) )
X est egale a Y
else
la difference entre X et Y est plus grande que la tolerance (les valeurs sont differentes)

Leffler
06-03-2009, 09:25 PM
Okey sure, but the method about looks alot cleaner to me

CGTalk Moderation
06-03-2009, 09:25 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.