Schroedingers-Hat / jsphys

Libraries for physics simulation on javascript canvas
GNU Affero General Public License v3.0
11 stars 1 forks source link

Doppler shift equation singularity #17

Closed Schroedingers-Hat closed 13 years ago

Schroedingers-Hat commented 13 years ago

The implementation of the doppler shift/light delay code has a bug here this.radialVPast = (this.XView[1] * this.V[1] + this.XView[2] * this.V[2]) / Math.sqrt(Math.pow(this.XView[1], 2) + Math.pow(this.XView[2], 2))/this.V[0];

This should behave as lim_(X0-->0) radialVPast=0. Instead we have a divide by 0 error. One option is to simply have a check and set it to 0 if it's small, but this is inelegant. Additionally we will still have round-off errors that could lead to odd unexplained behavior if you come too close to something. Especially if other methods of motion (ie. forces) are added.

I'm sure there is a less brain-dead way of doing this. For now the only ill effect is anything that happens to come to the point 0,0 will change color, or vanish off into the distance for a single frame, and then come back.

Schroedingers-Hat commented 13 years ago

One resolution is changing to polar coordinates. Using trig functions and passing an angle and radius to whatever needs it is another option, but atan is still divergent. Additionally they're more expensive computationally.

This is yet another reason keeping everything in vector form is a good idea. If I'd done that properly from the beginning then switching to polars would be a few lines. :/

Schroedingers-Hat commented 13 years ago

kludged for now, can't think of a smart way