CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Posts
    99

    Angry acos returns -1.#IND

    hello guys,

    in my program, i need to get the angle between two normals.
    i first get the dot product of the two normals and use acos to get the actual angle.

    the code is rather simple like this:

    float dot=Math:ot(normal1,normal2);
    printf("dot in2:%f\n",dot);
    angle=acos(dot);
    printf("angle1:%f\n",angle);


    i got the output:

    dot in2:1.000000
    angle1:-1.#IND00


    the weird thing is that the infinite result doesn't always happen when the dot is 1.000000. for example, one of the outputs was:

    dot in2:1.000000
    angle1:0.000598

    so i guess the float is rounded when being outputted.
    although in both cases, the dot values are 1, i guess they are not.


    and i also tried acos(1), the result is 0, not -1.#IND

    now i'm wondering, is that true the function acos can return -1.#IND.

    how can i avoid that?

    thank you.

  2. #2
    Join Date
    Jan 2006
    Posts
    99

    Re: acos returns -1.#IND

    i guess i know the answer,

    i tried acos(1.00020001f), the result was -1.#INF

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: acos returns -1.#IND

    Yeah, you need to clamp the value to the range [-1,1].

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured