GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Mar-2004, 22:15
jerry jerry is offline
New Member
 
Join Date: Mar 2004
Posts: 18
jerry is on a distinguished road

finding angle between 2 vector


hi...juz wanna ask whether any one of you knows how to calculate angle from 2 given vectors? my vectors are in the 3rd dimension (1,2,3) <-- something like this.

i got these codes...not sure whether it's correct.
can you guys chk for me?

CPP / C++ / C Code:
double AngleBetweenVectors(CVector3 Vector1, CVector3 Vector2) 
{ 
// Get the dot product of the vectors 
float dotProduct = Dot(Vector1, Vector2); 

// Get the product of both of the vectors magnitudes 
float vectorsMagnitude = Magnitude(Vector1) * Magnitude(Vector2) ; 

// Get the angle in radians between the 2 vectors 
double angle = acos( dotProduct / vectorsMagnitude ); 

// Return the angle in radians 
return( angle ); 
} 

  #2  
Old 23-Mar-2004, 22:17
jerry jerry is offline
New Member
 
Join Date: Mar 2004
Posts: 18
jerry is on a distinguished road
oh yes what is CVector3?
  #3  
Old 23-Mar-2004, 22:19
jerry jerry is offline
New Member
 
Join Date: Mar 2004
Posts: 18
jerry is on a distinguished road
and if my vectors they have negative values....is it still applicable?
  #4  
Old 23-Mar-2004, 22:48
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Well, I don't know how to find the angle, but I'm guessing CVector3 is a typedef'd 3d vector of some numeric type. Your code looks just fine. Have you tested it?
__________________
-Aaron
  #5  
Old 23-Mar-2004, 22:53
jerry jerry is offline
New Member
 
Join Date: Mar 2004
Posts: 18
jerry is on a distinguished road
oh....so how do i define CVector3? #define?
  #6  
Old 23-Mar-2004, 22:56
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Quote:
Originally Posted by jerry
oh....so how do i define CVector3? #define?
Create a 3d vector, then put the word typedef before it.

I believe this would do it...

typedef vector < vector < vector < int > > > Cvector3;
__________________
-Aaron
  #7  
Old 23-Mar-2004, 23:02
jerry jerry is offline
New Member
 
Join Date: Mar 2004
Posts: 18
jerry is on a distinguished road
oh so i juz create a new cpp file n typedef CVector3? damn...im such a C++ failure
  #8  
Old 23-Mar-2004, 23:04
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Quote:
Originally Posted by jerry
oh so i juz create a new cpp file n typedef CVector3? damn...im such a C++ failure

Yeah, but you have to know how to do a 3d vector first lol. I don't, so don't follow the example in the post above :-P
__________________
-Aaron
  #9  
Old 23-Mar-2004, 23:10
jerry jerry is offline
New Member
 
Join Date: Mar 2004
Posts: 18
jerry is on a distinguished road
oh man......
LOL~
alrite...at least i understand wat this whole vector thing is abt...
which means i have to manually calculate the angles now...
aaron, THANKS! Ur great!
  #10  
Old 24-Mar-2004, 01:20
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Well, I feel bad taking credit when I didn't really do that much to help you, so hopefully you are able to solve this problem
__________________
-Aaron
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2D vector tay C++ Forum 9 05-May-2004 15:56
Declaring a vector of vectors? Lethal411 C++ Forum 2 20-Mar-2004 09:02
vector prob nattylife C++ Forum 1 15-Nov-2003 07:41
vector sorting gotnospoon C++ Forum 0 10-Nov-2003 15:26
Something I have noticed about IE6 concerning site finding jrobbio Search Engine Optimization Forum 0 10-Mar-2003 08:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:39.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.