sin output 0 to 1, instead of -1 to 1

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 05 May 2003   #1
sin output 0 to 1, instead of -1 to 1

hiya, I'm trying to get the output of a sin function in an expression to vary from 0 to 1 instead of -1 to 1... i'm using it to control a blendshape and i don't want the negative value because of the effect it has on the blendshape...

i have tried clamp and abs functions, but these result in sharp flat sections in the output sin wave...

i also (in a very round about way - not too much experience with expressions...!!) tried using a setRange node, which worked although it meant the rest position for the wave was now at a value of 0.5!!!! half way thru my blendshape...

hopefully i'm missing somehting really obvious, anyone have any ideas...

tanks

james
 
Old 05 May 2003   #2
try this:

$mySin = sin(time);
$mySin = ($mySin + 1) / 2.0;

that should bring your sine value to a range of 0 to 1 without having the glitch in it.

cheers

alexx
 
Old 05 May 2003   #3


pure magic!

got it to work, all set now... so simple and yet so confusing to my mathematically challenged brain! back to grade 1 maths i go... 1+1 =...

(thanks +1) / 2.0



james
 
Old 05 May 2003   #4
You're better off multiplying by 0.5 than dividing by 2. Same results, but computationally less expensive
__________________
David Stripinis
Filmmaker
 
Old 05 May 2003   #5
David, unless you're making fun of me for always harping on performance...

Floating point multiply and divide take roughly the same amount of time. Time each of these with a stopwatch and see for yourself:

for ($x = 0; $x < 100000000; $x++)
{
float $z = 3;
float $y = ($z * 0.5);
}
print "done";


for ($x = 0; $x < 100000000; $x++)
{
float $z = 3;
float $y = ($z / 2);
}
print "done";

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators

Last edited by mark_wilkins : 05 May 2003 at 04:45 AM.
 
Old 05 May 2003   #6
cooool

two mel authors start the fight
 
Old 05 May 2003   #7
No way. David's as knowledgeable as they come, and there's no way I'd contradict him without double and triple-checking my facts.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
Old 05 May 2003   #8
I'm just coming off the mental place of games. It has to do with the number of cycles needed to calculate a divid vs the number of cycles needed to calculate a multiply. This is a tad more signifigant in games where every cycle is precious.

It could become much more of an issue if you had say 10,000 particles all running a expression with a divide in it vs a multiply.

Maybe our workstations are just too good?

Anyway, I've always been taught "don't divide", so, you know, I just don't.
__________________
David Stripinis
Filmmaker
 
Old 05 May 2003   #9
Getting off-topic a bit: don't FMUL and FDIV take the same number of cycles on a Pentium 4? Or is exception handling the issue?

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
Old 05 May 2003   #10
you could always use "absolute value" as well.

float $myVar = abs(sin(time));
__________________
`, ,`,
James Jacobs
 
Old 05 May 2003   #11
note that absolute value gives you different motion, by making the object suddenly reverse direction at the low point.

For many things, this may be just what you want, of course.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
Old 05 May 2003   #12
i think the best way is

$value=($inputcontrol%3.14159);
$value=-1.0*cos ($value);
$value=($value+1)/2.0;


this way when inputcontrol=0 the blend shape is 0
and the range value is between 0 and 1
__________________
larry@larryvizoso3d.com
 
Old 01 January 2006   #13
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:59 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.