View Full Version : getting rid of "e" in x,y,z coordinates

 artistx01 January 2004, 09:13 AMWondering if someone could help me out with a Format problem. I'm printing out points to a file, but I don't want the exponential printed out. I've notice this occuring with very small numbers in Max. For example, [-86.6734,6.41911e-007,16.7711] where the y component in the list has an exponent. I was hoping there was some easy command to get rid of this exponent and force the number to print out in decimal form, but I haven't found anything. I was wondering if someone could point me in the right direction. Am I missing something big here? I'm currently using a simple loop to decide if the number is smaller than a certain amount (let's say .00001 for example) if the number is smaller than that, then print out "0" in place of the exponential number. if MyPoint.y < .00001 do ( MyPoint.y = 0 print MyPoint.y ) Surely, there must be an easier way than this. Or is everyone else using a loop to convert their exponential numbers. Anyone know of a way to completely convert without losing any precision in the exponential number given different exponential values. Say a function that takes [7.24311e-008, 6.41911e-007, 12] and converts to [0.000000724311, 0.00000641911, 12]. Any help would be greatly appreciated. Thanks.
playmesumch00ns
01 January 2004, 11:40 AM
Why bother printing it out differently? You can read it back in fine like that, it makes it easier to read and it makes the file smaller.

artistx
01 January 2004, 03:03 PM
Hi playmesumch00ns. The output file isn't being read back into 3ds Max. The file is going to an external renderer. I'm using a renderman renderer. Far as I know, you can't put that 'e' in the rib file. That's why the exponential form has to be changed to a decimal form without the "e". Any ideas on how to do this?

stew
01 January 2004, 05:34 PM
What programming language/functions are you using to print the numbers?

artistx
01 January 2004, 06:20 PM
Hello Stew. I guess I should post in the Maxscript area. (it was a late night post and wasn't thinking too well).

I'm using the getKnotPoint function to grab the particular point that I need. Then I'm merely getting the nth component of the point(i.e. MyPoint.y). I'm using Maxscript's "Format" to output the x,y,z components of a point. I'm not using anything but Maxscript to work with the point data. Do others use additional languages as well to solve this exponent problem?

stew
01 January 2004, 07:13 PM
It's been a while since I worked with MaxScript, and I didn't touch "Format". However, what you need is to tell it to format the number with a fixed number of decimal points, that's how it works in most other languages. I had the exact same problem when writing an exporter in Python, and well, at least in Python it'd be "fpformat.fix(vert.Y(),8)" what creates a string representation of a float without exponential notation. I'm pretty confident that MaxScript has a similar function.

RealThing
01 January 2004, 07:30 PM
Maxscript doesn't have any control over precision so everything is single point precision. For this reason I'm not sure it's really cut out for a rib exporter since you would probably in some cases prefer to deal with double precision. In most cases it may not make a difference though but it's something to keep in mind.
I would also just round these numbers to 0 as these near 0 numbers are typically 0 but return these numbers due to precision errors. Since there are no number formating methods inside maxscript itself you'll have to do the formating yourself. Although an extension may exist that will do this and if there is it would be worth using. To do it by hand you would have to first test to see if the value contains an e. This would work for extreamly tiny and extremely large numbers. But testing for an e would mean converting to a string which you don't want to do unless you have to b/c it's slow. So I would suggest that you look to see how many digits max will take before it changes the formatting and do < and > tests on numbers since that woudl be much faster than converting to a string and doing string operations. Once it passes that logical statement you'll need to convert the number to a string and use string operations to seperate the mantissa and exponent and then reconstruct the proper number with all the digits.

stew
01 January 2004, 11:04 PM
Originally posted by RealThing
Since there are no number formating methods inside maxscript itself you'll have to do the formating yourself.
Is it just me or does using MaxScript really feel like this: :banghead: ?

RealThing
01 January 2004, 11:46 PM
Actually maxscript has alot more higher level functions compared to MEL. But if you factor in that most of the time you have an artist and not a TD using it often times it is like banging your head. Overall maxscript isn't too bad. I find it usefull anyhow.

stew
01 January 2004, 11:54 PM
Last time I was using MaxScript, it really felt like a slap-on solution. None of the scripts I recorded with the script recorder would execute properly, they all required hand-editing. And many of the things I needed were poorly documented. Of course, I guess the fact that it's not as popular as MEL is one reason why there are not as many tutorials for it. And the problems I had with the LISP (?) syntax is nothing I could blame discreet for.

artistx
02 February 2004, 05:05 AM
Thank you so much RealThing for replying. You stated what I was afraid of, concerning the single/double precision issue. Like you said, it wouldn't make a big difference in most cases, but in really really really large or small scenes it could come into play. One of these days I'm just going to have to take time and learn the Max SDK. It didn't take me long to construct my cute little export script though, and I've always feared it would take double or triple the time to do similar things in C++ and the SDK. I guess I'll just stick to cutting off the extremely small values and converting them to zero or the maximum limit number (like you suggested).

Thanks for the code bit Stew. Even though it's in Python, it's a similar setup, that code gives me an idea on how to use a converter function in Maxscript.

rendermaniac
02 February 2004, 12:27 PM
Most RIB files can have exponent format. In fact using Mtor I have often seen RIB files which have more precision than from MEL. I would definitely try it first - it might depend which renderer you are using. Exponent format is pretty standard.

Simon

Originally posted by artistx
Hi playmesumch00ns. The output file isn't being read back into 3ds Max. The file is going to an external renderer. I'm using a renderman renderer. Far as I know, you can't put that 'e' in the rib file. That's why the exponential form has to be changed to a decimal form without the "e". Any ideas on how to do this?

artistx
02 February 2004, 01:16 AM
Hello rendermaniac. Hmm. Perhaps I don't have to worry about converting after all. I didn't know exponential form was commonly acceptable for RIB files.

OC-NightHawk
02 February 2004, 02:37 AM
I don't know if this has been answered, but the E denotes scientic notation. If you want to convert into the decimal place then you need to multiply the number to the left of the e by 10 to the power denoted by the number to the right of the e. This usually results in either a huge or super small number. So if you are writing a program to write the rib files it would be as simple as reading the text string and grabing everything to the left and right of the e and inserting them into variables and plugin them into the function to generate a decimal number.

I hope this helped, good luck.

artistx
02 February 2004, 02:45 AM
Thanks OC-NightHawk for replying. Yeah, I was also thinking along those lines. Build a function that:
1. finds the "e" in the number,
2. looks to see if there's a negative number (and acting appropriately),
3.grabbing the number(s) after e,
4. and finally inserting that number into a multiplication equation which then spits out the new number which is no longer in scientific notation.

Well, that's the general idea atleast.

OC-NightHawk
02 February 2004, 06:03 AM
Well now that you know what you have to do it should be trivial to do the calculation. :beer: Let me know how it goes, I assume your using c++. :)

artistx
02 February 2004, 03:02 PM
Sure, OC-Nighhawk. I'll let you know how things turn out. :) Thanks again.

RealThing
02 February 2004, 05:06 PM
OC the problem is that he's using Maxscript so you can't treat it as a number but have to do this conversion as a string. I posted a couple functions to do this for him in the maxscript section. The other night. Raw number methods are of no use. But I would be surprised if RIBs don't support scientific notation.

OC-NightHawk
02 February 2004, 06:14 PM
Originally posted by RealThing
OC the problem is that he's using Maxscript so you can't treat it as a number but have to do this conversion as a string. I posted a couple functions to do this for him in the maxscript section. The other night. Raw number methods are of no use. But I would be surprised if RIBs don't support scientific notation.

He's using max script? I admit I haven't looked into it but surely it has string functions. If not making a plugin may be a better option.

RealThing
02 February 2004, 08:06 PM
The problem is Maxscript lacks any number formating functions. The number it gives you is the number it gives you and if you don't like it you'll need to convert the number to a string and manipulate it from there. Since a string doesn't care if it's a number or letter it's certainly doesn't know what scientific notation is. So this type of reformating is not easy or clean.

OC-NightHawk
02 February 2004, 02:36 AM
Originally posted by RealThing
The problem is Maxscript lacks any number formating functions. The number it gives you is the number it gives you and if you don't like it you'll need to convert the number to a string and manipulate it from there. Since a string doesn't care if it's a number or letter it's certainly doesn't know what scientific notation is. So this type of reformating is not easy or clean.

So there are text functions. Then it doesn't matter as long as you can run a logic statement and check if its a number character. Keeping it clean may prove to be a challenge but just because its possible it will be difficult doesn't mean its not worth doing. Beyond that a machine doesn't actually understand what anything it just does what its told.

rendermaniac
02 February 2004, 09:49 AM
Maxscript isn't alone in having poor formatting support. Maya's MEL has no sprintf fuction and it is extremely frustrating having to bodge something together yourself.

If you need to manipulate the numbers then this is a problem, but surely you are just dumping them straight out as blind data?

Simon

OC-NightHawk
02 February 2004, 02:00 AM
No I was just brainstorming how artistx could go about doing what he wanted to do. I will take this moment to point out though that scripting is just scripting. :D

CGTalk Moderation
01 January 2006, 08:00 AM
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.

1