Click to See Complete Forum and Search --> : Overflow check in Java?
Malone
09-30-2003, 01:04 AM
Is there a way to check for overflow of doubles in java? I'm working on a Raytracing application and I'm getting some anomolies with portions of infinite planes showing up where they shouldn't be. I've deduced that this is because the z value of the intersection of a ray and the plane x = constant, for instance, overflows for some rays. This causes the intersection distance to be less than it actually is, so the color of that plane shows up instead of the color of a different (correct) object.
So I'd like to detect overflow and throw away that intersection value if possible. Any ideas?
Here's a pic, so you see what I mean.
The Green plane is z = 300.0
The Blue plane is y = -50.0
So they should meet at a horizontal line and the green one should go all the way to the top, but the blue one interferes.
Image (http://www.pitt.edu/~mpr22/big_sphere.jpg)
I can post code if you want, but I really think it's just the overflow thing that's the problem.
The Double class has static fields: Double.NaN, Double.NEGATIVE_INFINITY, and Double.POSITIVE_INFINITY. It also has static methods isInfinite(double v) and isNaN(double v).
I'm not familiar with raytracing, but checking programmatically for these values is straightforward. You might want to insert some debugging info first to narrow down the values you need to check.
EverlastingGod
09-30-2003, 10:25 AM
Originally posted by Malone
Here's a pic, so you see what I mean.
The Green plane is z = 300.0
The Blue plane is x = -50.0
So they should meet at a horizontal line and the green one should go all the way to the top, but the blue one interferes.
Image (http://www.pitt.edu/~mpr22/big_sphere.jpg)
Which way are your axes going? Usually x is right, y is up and z is out of the screen (or into the screen for left handed coordinates). So I don't think that is what you should be getting... Unless your center and/or direction of projection is is not down the z-axis.
Of course you may just have a rounding error (you know how floats are ;))
Malone
09-30-2003, 12:13 PM
Yeah, I've got a left handed coordinate system. (+x is right, +y is up, +z is into the screen). Thanks rock, I'll look into the Double class stuff.
*correction*
the equation of the blue plane is actually y = -50.0
(I had typed x = -50.0 originally, sorry)
EverlastingGod
09-30-2003, 01:13 PM
Originally posted by Malone
*correction*
the equation of the blue plane is actually y = -50.0
(I had typed x = -50.0 originally, sorry)
That's good, I was really confused before.
Can you tell that I totally ignored all that stuff? ;)
Nice picture, though. :D
Malone
09-30-2003, 06:34 PM
Found the problem! I was forgetting to throw away values of 't' that are negative when testing for plane intersection. It had nothing to do with overflow. Thanks for your help anyway!
EverlastingGod
10-01-2003, 09:05 AM
Originally posted by rock
Can you tell that I totally ignored all that stuff? ;)
Nice picture, though. :D
I was just trying to figure out why his description didn't match the image at all. (Turned out the picture wasn't wrong, the description was.)
The left handed and right handed coordinate system refers to the directions the axes are going. Your thumb is +x, index finger is +y, other fingers are +z. When you use your right hand, right is +x, up is +y and out of the screen is +z. When you use your left hand, right is +x, up is +y, and into the screen is +z.
Originally posted by EverlastingGod
Your thumb is +x, index finger is +y, other fingers are +z. When you use your right hand, right is +x, up is +y and out of the screen is +z.
Wait, so +x = thumb = up. +y = index finger = forward.
Now, +z = other finger = curled back and pointing at me, so that's backward, right? So +z = -y? :p
Just kidding by the way. You get pretty darn used to the whole right-handed coordinate system by the end of your first semester as an ME major. :D
Another use of the right hand - take the thumb as pressure and the fingers as direction of circulation. In the northern hemisphere, use the right hand and you see that flow circulates CCW around a low pressure system and clockwise around a high. Use the left hand if you're in New Zealand.
naper2000
10-09-2003, 07:17 PM
What did you mean bout the right hand thing are you referring to his picture or thing he made or to a real right hand?
P.S. i didnt understand much about wat you guys were talking bout lol!
And one more thing rock wats an ME ??
Originally posted by naper2000
What did you mean bout the right hand thing are you referring to his picture or thing he made or to a real right hand?
P.S. i didnt understand much about wat you guys were talking bout lol!
And one more thing rock wats an ME ??
The "right hand thing" is the coordinate system. If you picture a regular x-y graph, the z axis could be coming up out of the page (right-handed) or down into the page (left-handed). In the end, it doesn't matter since it's just a convention - but it makes sure everyone is speaking the same language.
ME = Mechanical Engineer