answer to formula = NaN?

0 favourites
  • 11 posts
  • Either I'm asking way too much of Construct2, or I'm just really bad at translating formulas.

    So what I'm trying to do is get these formulas into C2:

    <img src="https://dl.dropboxusercontent.com/u/48563442/Bodyshapes-3D-2D-formules.jpg" border="0" />

    But when I insert the values for q and z through variables the formula returns NaN (not a number), which is strange because the formula as I've put into C2 should consist only of numbers. Even when I manually change all z's and q's to numbers the outcome stays NaN.

    So I might just have put in the formulas the wrong way, or I'm pushing C2 beyond it's limits.

    Here are the formulas as I've entered them in C2:

    formula for a:

    abs((-6*z+((6*q*z)/(q-100)-sqrt((16*((q^2)*(z^2)-((100*q*z)^2)-((7500*z)^2))))))/2/(-6+((8*q)/(q-100))-(((6*q)^2)/((q-100)^2))))

    formula for b:

    abs(-(-6*z+((6*q*z)/(q-100)-sqrt((16*((q^2)*(z^2)-((100*q*z)^2)-((7500*z)^2))))))/2/(-6+((8*q)/(q-100))-(((6*q)^2)/((q-100)^2)))*q/(q-100))

    any advise would be appreciated.

  • NaN is the correct answer if you do something like divide by zero, which would happen if q is 100.

  • I understand that, but:

    q is always larger than 50 and smaller than 100

    z is always larger than 0

  • could you break it down and see if construct is any happier in smaller chunks

    a=-6*z

    b=(6*q*z)

    c=q-100

    etc

    and stitch it all back together ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • RamPackWobble

    I guess that's worth a try, I was thinking of that but hoped it wouldn't be necessary, because it means adding a lot of local variables, but well..

  • I copied your formula into Excel, and replaced Q and Z with numbers. Although Excel accepts the various functions, it came back with a NAME$ error.

  • removed post as already suggested/done above

  • Yep.. somewhere, somehow, there must have been a translation-error..

    bah.. humbug..

  • Yeah with a quick look over the main thing you missed was adding a "-" inside the sqrt. Without it you're calculating the sqrt of a negative number which is NAN. I can look over it better tomorrow.

    What's the formula calculate?

  • Rereading the formula I missed a lot, haha..

    But it all seems to go wrong with the square root.

    Working on it!

    The formulas are a bit of pseudo-code to calculate the major axis and minor axis of an ellips from it's perimeter.

    z is the perimeter divided by pi and q is a percentage so a+b always add up to 100%

  • By George, I think I've got it!

    It was indeed the negative inside the square root that was ruining the party..

    Added abs() instead of the missing minus (which would have worked) and all seems to be working just fine.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)