Re: [Algorithms] floats, doubles, epsilons, joy
Brought to you by:
vexxed72
From: Gil G. <gg...@ma...> - 2000-08-31 19:34:28
|
I wouldn't use doubles, they just obscure the problem but don't eliminate it. If an algorithm is unstable with floats, it is usually unstable with doubles too. So, how to solve the problem? The only solution is carefully analize the situation and do things robustly. That isn't very helpful, but it is true, you gotta really think about the situation to solve the problem. I solve your collision problem like this typically. I don't attempt to rest directly on the floor, I attempt to hover .1 inches or so off the floor. Therefore, even with floating point inaccuracy, I never find I am IN the floor at the start of the next round. This does use a tolerence, but it is subtly different than your approach. Your approach attempts to correct the problem after is occurs and my approach is proactive, insuring the problem does not occur. (This all assumes finding yourself in the floor is the problem). Even if you get this problem licked, if you are doing anything interesting, like say having things push the player, you will run into half a dozen other more subtle problems. You gotta think through each one to figure out how to solve the problem with inexact arithmatic. It is really really hard work. -Gil > I've been working on some collision stuff lately and I keep running into > problems with floating point inaccuracies. Specifically if the player is > standing on top of a triangle, the distance should be zero, but with float > it was very close to zero but not quite. So I converted all my code to use > double and its much better but I'm still not getting exactly zero. With > float they were large enough to cause unwanted movement, with double they > are tiny but I can easily imagine the player finding a way to make these > values be higher than my epsilon amount (0.00001). Just so everyone knows, > I'm doing ellipsoid vs. triangle collision with an algorithm I found on > Flipcode (http://www.flipcode.com/tutorials/tut_coll-ellipsoids.shtml). > > This is the first time I've run into this, I'm wondering if there are some > common ways to get around these types of problems? > > Also I was wondering if there was a down side to using doubles rather than > floats. This code doesn't use any ram so size doesn't matter, but is doing > floating point math with doubles much slower or have other unwanted side > effects? > > Thanks for any suggestions, > > - Jason Zisk > - nFusion Interactive LLC > > > > > > > > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list |