Results 1 to 4 of 4

Thread: Not opengl related but can somebody help???

  1. #1
    Senior Member Regular Contributor
    Join Date
    Oct 2005
    Posts
    137

    Not opengl related but can somebody help???

    How can I find the angle between 2 vectors in 3D space. I mean if i am trying to find the angle between up vector (0,1,0) and a vector (1,1,0) using the formula
    @ = cos^-1 (a dot b)/ |a|.|b|
    then suppose the angle comes to be around 45 but the angle between (0,1,0) and (-1,1,0) also comes to be 45 while it should be -45. So does anybody know of a way through which I can get actual angle between up vector and another vector or is there a way to identify that the 45 angle in the second case is actually -45??? waiting for your reply.... Please help.....!

    Fastian

  2. #2
    Member Newbie
    Join Date
    May 2001
    Location
    Hungary
    Posts
    30

    Re: Not opengl related but can somebody help???

    The problem is that cos(x)=cos(-x).

    Your problem can be easily solved, but my method is not too efficient(it's just what popped in my mind right now, if I find a more simple one, I'll let you know).

    Let the two vectors be u and v. We want to find the counterclockwise angle between u, and v in that order. Simply to speak we want to see if v is "below" u or "above" it.
    We calculate w=u x v. Then w and u specify a plane, its normal is n=w x u. If v points "down" from the plane then s=(v dot n) is negative. Otherwise its positive. You can now simply calculate the angle :

    angle=sign(s)*cos^-1((u dot v)/(|u|*|v|))

    It's possible that I mixed up u and v, or w and u in their cross product. Please try each possibility.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    319

    Re: Not opengl related but can somebody help???

    There is no correct "angle between vectors". The angle is always up to a sign. That's because you can look at the vectors from two different directions, and get opposite (or complementary) angles.

    What kistompika suggested is a good start, but I'll modify it a bit. Calculate w = u x v, then multiply the resulting vector by the normal to the plane you're interested in comparing angles on (for example, your view direction if your screen is the plane). Then check the sign. I always mix my signs, so I won't tell you which is which - check it yourself

    Maybe there's a simpler way, but that's the way I do it (well, actually, I first project both vectors to the plane, then measure the angle, but both versions can be useful for different things).

    [This message has been edited by ET3D (edited 05-21-2001).]

  4. #4
    Member Newbie
    Join Date
    Dec 2000
    Location
    Donetsk, Ukraine
    Posts
    48

    Re: Not opengl related but can somebody help???

    If you always know, what angle you need, you should use methods defined above. But I am not sure, that for any vectors in 3d space you know for sure, which angle you need from "this" side or from "opposite" one. If you just need angle and dont want to make any operations with it, take it absolute value...

Similar Threads

  1. related to OpenGL SC 1.0.1
    By Chaitra CJ in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-07-2012, 04:57 AM
  2. not opengl related but I need help for my fps counter
    By Bra'Tac in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 05-15-2001, 05:47 AM
  3. MFC problem (not really OpenGl related... please help)
    By clucches in forum OpenGL: Advanced Coding
    Replies: 16
    Last Post: 04-20-2001, 09:18 AM
  4. Possible OpenGL related crash
    By in forum OpenGL: User Software
    Replies: 16
    Last Post: 09-21-2000, 09:48 AM
  5. New OpenGL related site!!!
    By romka in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-25-2000, 02:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean