PDA

View Full Version : How to get rid of division by zero?


StuStix
11-08-2009, 05:53 PM
Hi, I am working on a script that analyses curvature continuity on a nurbscurve.

this works:

string $exp = ($curve+".controlPoints[1].zValue = (10/"+$infoNode+".curvatureRadius);");

expression -s $exp;

but there is a 'division by zero' situation if curvatureRadius becomes zero so...

I thought I could use a condition 'if statement':

string $exp = ("if ($infoNode.curvatureRadius==0)"
+"$curve_porc.controlPoints[1].zValue=0;"
+"\r\n else \r\n "
+"$curve_porc.controlPoints[1].zValue = (10/"+$infoNode+".curvatureRadius);");

expression -s $exp;

Syntax error //

the expression works if I make it in the expression editor but I can't get it right
when using the variables within Mel

any ideas? ...pls

sincerely
Mel Newbie

benio33
11-09-2009, 07:54 AM
string $exp = "if (" + $infoNode + ".curvatureRadius==0) \\n" +
$curve_porc + ".controlPoints[1].zValue=0;\\n"+
"else \\n"+
$curve_porc + ".controlPoints[1].zValue = (10/"+$infoNode+".curvatureRadius);" ;

expression -s $exp;

try this

StuStix
11-09-2009, 11:15 AM
1000 thanks for help!!!

it works


string $exp = "if (" + $infoNode + ".curvatureRadius==0) \n" +
$curve_porc + ".controlPoints[1].zValue=0;\n"+
"else \n"+
$curve_porc + ".controlPoints[1].zValue = (10/"+$infoNode+".curvatureRadius);" ;

expression -s $exp;

berniebernie
11-09-2009, 04:30 PM
you can use the shorthand if then operator in maya to reduce code length (not readability)

for instance

//returns 1
a = 0;
a = (a==0)?1:a;


//returns 2
a = 2;
a = (a==0)?1:a;

CGTalk Moderation
11-09-2009, 04:30 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.