Overflow check in Java?

Sharky Forums


Results 1 to 11 of 11

Thread: Overflow check in Java?

  1. #1
    Tiger Shark
    Join Date
    Oct 2000
    Location
    Erie, PA, USA
    Posts
    693

    Overflow check in Java?

    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

    I can post code if you want, but I really think it's just the overflow thing that's the problem.
    Last edited by Malone; 09-30-2003 at 12:14 PM.
    AMD AthlonXP 2600+ Thoroughbred B @ 200x10.5
    Shuttle AN35N nForce2 Ultra 400
    2x512MB Kingston PC3200 (3-3-3)
    ATI Radeon 9600 Pro
    40GB WD ATA-100 8MB cache
    Creative 12X DVD Drive
    Memorex 52X CD-RW
    Running Windows XP Pro

  2. #2
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    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.

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

  3. #3
    Hammerhead Shark EverlastingGod's Avatar
    Join Date
    Feb 2003
    Location
    MD
    Posts
    1,364

    Re: Overflow check in Java?

    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
    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 )
    Stay cool
    and be somebody's fool this year

  4. #4
    Tiger Shark
    Join Date
    Oct 2000
    Location
    Erie, PA, USA
    Posts
    693
    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)
    Last edited by Malone; 09-30-2003 at 12:15 PM.
    AMD AthlonXP 2600+ Thoroughbred B @ 200x10.5
    Shuttle AN35N nForce2 Ultra 400
    2x512MB Kingston PC3200 (3-3-3)
    ATI Radeon 9600 Pro
    40GB WD ATA-100 8MB cache
    Creative 12X DVD Drive
    Memorex 52X CD-RW
    Running Windows XP Pro

  5. #5
    Hammerhead Shark EverlastingGod's Avatar
    Join Date
    Feb 2003
    Location
    MD
    Posts
    1,364
    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.
    Stay cool
    and be somebody's fool this year

  6. #6
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    Can you tell that I totally ignored all that stuff?
    Nice picture, though.

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

  7. #7
    Tiger Shark
    Join Date
    Oct 2000
    Location
    Erie, PA, USA
    Posts
    693
    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!
    AMD AthlonXP 2600+ Thoroughbred B @ 200x10.5
    Shuttle AN35N nForce2 Ultra 400
    2x512MB Kingston PC3200 (3-3-3)
    ATI Radeon 9600 Pro
    40GB WD ATA-100 8MB cache
    Creative 12X DVD Drive
    Memorex 52X CD-RW
    Running Windows XP Pro

  8. #8
    Hammerhead Shark EverlastingGod's Avatar
    Join Date
    Feb 2003
    Location
    MD
    Posts
    1,364
    Originally posted by rock
    Can you tell that I totally ignored all that stuff?
    Nice picture, though.
    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.
    Stay cool
    and be somebody's fool this year

  9. #9
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    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?


    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.

    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.

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

  10. #10
    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 ??

  11. #11
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    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

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •