Strange oscillations

What did you draw?
exfret
Posts: 585
Joined: Sun Jul 28, 2013 8:40 pm

Strange oscillations

Post by exfret »

I was doing something way far out with r^2, and something unexpected happened:

Code: Select all

Gravity Fun at TestTubeGames.com: [ForceG: 2,Qual: 1,Zoom: 0.1,xSet: -1219.65,ySet: -1756.35], [x0: -30,y0: 50,vx: 0,vy: 0,t0: 0,who: 1,m: 1000], [x0: 5166.2,y0: 4582.2,vx: 0.14,vy: -0.17,t0: 10,who: 3,m: 0]
Look at the ends of its orbit, it creates a sort of 'wave' thing. Why is this? Is this just mis-precision? Also, I noticed that when you go across the screen (drag the mouse), the part you were already looking at becomes brighter (probably due to drawing the lines again).
Nobody ever notices my signature. ):
A Random Player
Posts: 523
Joined: Mon Jun 03, 2013 4:54 pm

Re: Strange oscillations

Post by A Random Player »

exfret wrote:I was doing something way far out with r^2, and something unexpected happened:

Code: Select all

Gravity Fun at TestTubeGames.com: [ForceG: 2,Qual: 1,Zoom: 0.1,xSet: -1219.65,ySet: -1756.35], [x0: -30,y0: 50,vx: 0,vy: 0,t0: 0,who: 1,m: 1000], [x0: 5166.2,y0: 4582.2,vx: 0.14,vy: -0.17,t0: 10,who: 3,m: 0]
Look at the ends of its orbit, it creates a sort of 'wave' thing. Why is this? Is this just mis-precision? Also, I noticed that when you go across the screen (drag the mouse), the part you were already looking at becomes brighter (probably due to drawing the lines again).
Looks like just mis-precision. Try making something similar but smaller and see if it happens. Or wait a few weeks until I can make a script to shrink or speed up codes.
And the lines do seem weird. Maybe Andy put it there so the lines wouldn't flash when you move.
$1 = 100¢ = (10¢)^2 = ($0.10)^2 = $0.01 = 1¢ [1]
Always check your units or you will have no money!
exfret
Posts: 585
Joined: Sun Jul 28, 2013 8:40 pm

Re: Strange oscillations

Post by exfret »

I would think that it was misprecision, but the planet follows such a predictable path. I can't think of anything else that it would be, but how would mis-precision cause this?
Nobody ever notices my signature. ):
User avatar
testtubegames
Site Admin
Posts: 1148
Joined: Mon Nov 19, 2012 7:54 pm

Re: Strange oscillations

Post by testtubegames »

Curious. It seems this has to do with how the drawing is executed. The orbital lines are added once per frame. The calculations of where-the-asteroid-should-be are done ~80 times per frame (depending on the 'quality' you're running at). Since the asteroid is zooming so fast, 'once per frame' is not quite often enough to be *sure* that you'll catch the asteroid at its outermost point. Sometimes it is a little closer to the sun when the orbit line is drawn. (For the record, it is drawn from the previous frame's position, to the current frame's position)

As for the lines getting darker, this definitely exists, though I haven't nailed down exactly why. Likely it comes from some rule I've put in place, such as "redraw a line if an endpoint had been off the screen". This means it will redraw over the part of that line that had been on the screen... making it thicker/darker/brighter. Especially noticeable in a setup like yours where the line segments are very long.
exfret
Posts: 585
Joined: Sun Jul 28, 2013 8:40 pm

Re: Strange oscillations

Post by exfret »

First of all, I can understand your explanation of why some lines go further than others, but why is it in such a regular, oscillating patter? That is my real question to you.

Secondly, I thought that maybe the redrawing of lines was just because you didn't draw over the previous lines, so they were still there when you redrew them or something like that. Of course, you have a better idea of how your code works than I do.

Finally, Have a Happy Tauesday!!! :D
Nobody ever notices my signature. ):
User avatar
testtubegames
Site Admin
Posts: 1148
Joined: Mon Nov 19, 2012 7:54 pm

Re: Strange oscillations

Post by testtubegames »

exfret wrote:First of all, I can understand your explanation of why some lines go further than others, but why is it in such a regular, oscillating patter? That is my real question to you.

Secondly, I thought that maybe the redrawing of lines was just because you didn't draw over the previous lines, so they were still there when you redrew them or something like that. Of course, you have a better idea of how your code works than I do.
Ah, why is it a regular pattern? Well, we've got two periods... one being the time it takes the planet to orbit the star (or get flung wildly, in this case). Let's say that's 1.00 seconds. The other is the time between frames in the game... it's a lot smaller than the first time span, so let's say it's .09 seconds.

We start at the outermost point. The planet goes through an orbit in 1.00 seconds... but the last picture was taken at 0.99 seconds, so the planet doesn't appear to be quite at its outermost point this time. The next time it comes around is 2.00 seconds... but the last picture was at 1.98 seconds, so the place it was drawn on the screen was a bit closer in again. At 3.00 seconds, the closest picture is at 2.97 seconds... closer still to the star. At 4.00 seconds, the frame is drawn at 3.96 seconds... closer again. And then at 5.00 seconds, the nearest frame to that moment is drawn at 5.04 seconds. So the planet is a bit further out again...

And this keeps going in cycles of course. The outermost point gets closer, then further, then closer. It's just because we have two time scales that don't line up perfectly every time through an orbit.
exfret wrote:Finally, Have a Happy Tauesday!!! :D
I'll wish you a whole Happy Weak (force)
exfret
Posts: 585
Joined: Sun Jul 28, 2013 8:40 pm

Re: Strange oscillations

Post by exfret »

Haha! Very funny. I see now why it is oscillating like that. The oscillations seem so soothing...
Nobody ever notices my signature. ):
DavidAllyn68
Posts: 28
Joined: Thu Aug 01, 2013 2:28 pm

Re: Strange oscillations

Post by DavidAllyn68 »

So, my thought was how the vectors are calculated rather than frame rate. I really don't mess with the R, but I've seen this before -- and it seems to only happen when there is "extreme" gravity. So, to test this, I've set up an oscillator "lab" with 9 stars all at m:5000. Basically simulating that same extreme environment, but a slower speed.

Try it out... Anywhere you start an asteroid, you get the oscillation:

Code: Select all

Gravity Fun at TestTubeGames.com: [ForceG: 2,Qual: 2,Zoom: .5,xSet: 1,ySet: 0], [x0: 0,y0: 0,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: -100,y0: 0,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 100,y0: 0,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 0,y0: -100,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 0,y0: 100,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: -72,y0: 72,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 72,y0: -72,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: -72,y0: -72,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 72,y0: 72,vx: 0,vy: 0,t0: 0,who: 1,m: 5000]
Then, I zoomed in on one of my attempts:

Code: Select all

Gravity Fun at TestTubeGames.com: [ForceG: 2,Qual: 2,Zoom: 3.04,xSet: 168,ySet: -187], [x0: 0,y0: 0,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: -100,y0: 0,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 100,y0: 0,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 0,y0: -100,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 0,y0: 100,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: -72,y0: 72,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 72,y0: -72,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: -72,y0: -72,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: 72,y0: 72,vx: 0,vy: 0,t0: 0,who: 1,m: 5000], [x0: -131,y0: 238,vx: 3.65,vy: -4.2,t0: 0,who: 3,m: 0]
So to make sure this was the reason, I removed all but one star and ran the same test:

Code: Select all

Gravity Fun at TestTubeGames.com: [ForceG: 2,Qual: 2,Zoom: 3.04,xSet: 168,ySet: -187], [x0: 0,y0: 0,vx: 0,vy: 0,t0: 0,who: 1,m: 5000],[x0: -131,y0: 238,vx: 3.65,vy: -4.2,t0: 0,who: 3,m: 0]
As you can see, when there is "extreme" gravity involved, the "oscillation" is actually the variance in the 2 or 3 points trying to describe the "ends" of the ellipse. Where those points are placed in relation to the orbiting vector does cycle so it appears that there is an oscillation of the orbit. As the number of points that would describe the ends of the ellipse increase, the less this "oscillation" would occur.

Now, why the program is using only a few points in "extreme" gravity is another question that I defer to Andy to answer. :ugeek:

-Dave
exfret
Posts: 585
Joined: Sun Jul 28, 2013 8:40 pm

Re: Strange oscillations

Post by exfret »

Your tests didn't have much evidence of oscillation, especially the third one, but I see what you mean. Also, I like your idea of having more precise measurements at greater velocities/accelerations/gravity, because it really makes sense. I hope Andy will incorporate it into his new version of the gravity simulator.
Nobody ever notices my signature. ):
User avatar
testtubegames
Site Admin
Posts: 1148
Joined: Mon Nov 19, 2012 7:54 pm

Re: Strange oscillations

Post by testtubegames »

DavidAllyn68 wrote: :ugeek:

-Dave
Okay, first off, that face is awesome!

And yeah, I think that's a nice, different look at why we saw the 'oscillations'. Where there is extreme gravity (aka... extreme accelerations (aka... fast-moving objects not-moving-in-a-straight-line)), we start to notice the fact that only one point is drawn on the screen per frame. In other situations, it doesn't matter... if the asteroid were moving in a straight line, you'd never notice. But at the end points of very thin orbits, it clearly does matter.

I think I should be able to improve upon that in the next version. It never really came up to me in the current version, since when I made the line-drawing algorithm, there were no positive exponent force laws. So the only places you'd get extreme gravity would be very close to a star... and at that point you wouldn't see the lines much anyway -- since the star blocked most of them.
Post Reply