Same calculation different results

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 03 March 2013   #1
Same calculation different results

I need a sanity check! This is a code fragment that's part of a position script controller. It's been giving me nightmares. To troubleshoot, I've temporarily put in two print statements to check my calculations. They should print the same results, but they don't! The first is giving me a very small value (0.99969d0). The second gives me a very large value (1.43784d+008). I'm sure I'm doing something stupid in my code, but I'm stuck. What am I doing wrong?

The first print takes the form of Print (calculation)
The second is variable=(same calculation)
print variable

Print statements are near the bottom.

Thanks in advance!


fn getTrueAnomaly satellite inMeanAnomaly = ( 
			result = #(0.0d-0,0.0d-0,0.0d-0)
			local kAccuracyToComputeE0To = 2d-13
			local kFarTooManyLoops = 100
			local dE = 0d-0
			local E0 = inMeanAnomaly
			local count =0
			do (
				dE = ((inMeanAnomaly + satellite.tledata.eccentricity * sin(E0) - E0) / (1.0 - satellite.tledata.eccentricity * cos(E0)))
				E0 = E0 + dE
				count +=1
				)
				while ((abs(dE) > kAccuracyToComputeE0To) and count < kFarTooManyLoops) 
			local cosOfE0 = cos(E0)
			local theX = (cosOfE0 - satellite.tledata.eccentricity)
			local theY = sqrt((1.0 - satellite.tledata.eccentricity) * (1.0 + satellite.tledata.eccentricity)) * sin(E0)
			result[1] = 0.0
			result[2] = mod2pi(atan2 theY theX)
			result[3] = (1.0 - satellite.tledata.eccentricity * cosOfE0) * (satellite.tledata.semiMajorAxis as double)  
			print (1.0 - satellite.tledata.eccentricity * cosOfE0) * (satellite.tledata.semiMajorAxis as double)
			print result[3]
			result
			)
 
Old 03 March 2013   #2
Originally Posted by BradT: I'm sure I'm doing something stupid in my code, but I'm stuck. What am I doing wrong?


 fn getTrueAnomaly satellite inMeanAnomaly = ( 
 			result = #(0.0d-0,0.0d-0,0.0d-0)
 			local kAccuracyToComputeE0To = 2d-13
 			local kFarTooManyLoops = 100
 			local dE = 0d-0
 			local E0 = inMeanAnomaly
 			local count =0
 			do (
 				dE = ((inMeanAnomaly + satellite.tledata.eccentricity * sin(E0) - E0) / (1.0 - satellite.tledata.eccentricity * cos(E0)))
 				E0 = E0 + dE
 				count +=1
 				)
 				while ((abs(dE) > kAccuracyToComputeE0To) and count < kFarTooManyLoops) 
 			local cosOfE0 = cos(E0)
 			local theX = (cosOfE0 - satellite.tledata.eccentricity)
 			local theY = sqrt((1.0 - satellite.tledata.eccentricity) * (1.0 + satellite.tledata.eccentricity)) * sin(E0)
 			result[1] = 0.0
 			result[2] = mod2pi(atan2 theY theX)
 			result[3] = (1.0 - satellite.tledata.eccentricity * cosOfE0) * (satellite.tledata.semiMajorAxis as double)  
 			print ((1.0 - satellite.tledata.eccentricity * cosOfE0) * (satellite.tledata.semiMajorAxis as double))
 			print result[3]
 			result
 			)
 

check the brackets.
 
Old 03 March 2013   #3
Thanks DenisT. I knew I was doing something stupid. Now that my checks are behaving as expected, I can get on with figuring out why it isn't working as expected overall. :-D
 
Old 03 March 2013   #4
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.
 
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 05:14 PM.


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