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

 05 May 2003 james THP New Member 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 share quote
 05 May 2003 alexx Yes, I Listen... as asd asdf Afghanistan 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 share quote
 05 May 2003 james THP New Member 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 share quote
 05 May 2003 dstripinis Frequenter David Stripinis TD Double Negative United Kingdom You're better off multiplying by 0.5 than dividing by 2. Same results, but computationally less expensive __________________ David Stripinis Filmmaker share quote
 05 May 2003 mark_wilkins Scream. 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. share quote
 05 May 2003 alexx Yes, I Listen... as asd asdf Afghanistan cooool two mel authors start the fight share quote
 05 May 2003 mark_wilkins Scream. 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 share quote
 05 May 2003 dstripinis Frequenter David Stripinis TD Double Negative United Kingdom 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 share quote
 05 May 2003 mark_wilkins Scream. 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 share quote
 05 May 2003 James Jacobs James Jacobs Ziva Dynamics Vancouver, Canada you could always use "absolute value" as well. float \$myVar = abs(sin(time)); __________________ ¤º°`°º¤ø,¸ ¸,ø¤º°`°º¤ø,¸ James Jacobs share quote
 05 May 2003 mark_wilkins Scream. 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 share quote
 05 May 2003 larryvm moving around the world   portfolio fernando vizoso TD el ranchito Madrid, Spain 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 share quote
 01 January 2006 CGTalk Moderation Expert 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. share quote

 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 vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.