Raised This Month: $32 Target: $400
 8% 

Difference between 2 angle vectors?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 07-27-2010 , 22:21   Difference between 2 angle vectors?
Reply With Quote #1

I don't fully understand vectors :S

Basically, I have one angle vector which I got from the client's eye angles.

Code:
GetClientEyeAngles
Then I have another angle vector which is the correct angle for the client's eyes to be looking at another point.

Code:
MakeVectorFromPoints(ClientEyes, OtherPoint, VectorConnecting);
GetVectorAngles(VectorConnecting, VectorAngles);
What I want to be able to do now, is to figure out if the different between both angle vectors is less than 75 degrees in all directions, but for the life of me I can't figure out how. Any help?
__________________
almcaeobtac is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 07-27-2010 , 22:51   Re: Difference between 2 angle vectors?
Reply With Quote #2

Quote:
Originally Posted by almcaeobtac View Post
I don't fully understand vectors :S

Basically, I have one angle vector which I got from the client's eye angles.

Code:
GetClientEyeAngles
Then I have another angle vector which is the correct angle for the client's eyes to be looking at another point.

Code:
MakeVectorFromPoints(ClientEyes, OtherPoint, VectorConnecting);
GetVectorAngles(VectorConnecting, VectorAngles);
What I want to be able to do now, is to figure out if the different between both angle vectors is less than 75 degrees in all directions, but for the life of me I can't figure out how. Any help?
I'm not all to sure what you want.
If you want to see if the Vector Angles of the second one (VectorAngles) versus the ones from GetClientEyeAngle are within 75° of eachother on each plane, can't you just substract absolutes and see if it's below 75?




Side note: I'm guessing GetVectorAngles gets the angles of the line connecting (0,0,0) with the given vector, right? Because I have no idea how you'd get the angles of a single point any other way x)
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 07-28-2010 , 00:35   Re: Difference between 2 angle vectors?
Reply With Quote #3

No I'm getting the angle from one point to another. IE the Client's eyes to another point. VS. the client's eyes in their current angle, but I'll try your method. How do you subtract absolutes, is it just | |?
__________________
almcaeobtac is offline
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 07-28-2010 , 00:40   Re: Difference between 2 angle vectors?
Reply With Quote #4

Also...360 degrees and 1 degree wouldn't register as being within 75 degrees of each other, even though they are in actuality. How would I work around that too?
__________________
almcaeobtac is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 07-28-2010 , 01:00   Re: Difference between 2 angle vectors?
Reply With Quote #5

Quote:
Originally Posted by almcaeobtac View Post
Also...360 degrees and 1 degree wouldn't register as being within 75 degrees of each other, even though they are in actuality. How would I work around that too?
Seeing how you're working with floats, use the FloatAbs() function to get absolutes.
To get around the 360-1 problem, use an || with a 360 increase on values (both, or you'd have to check which one is highest first, which is a lot more work)
It would look something like this:
PHP Code:
if( FloatAbs( (Angles1[0] - Angles2[0]) ) < 75.0 
|| FloatAbs( (Angles1[0] - (Angles2[0] + 360.0) ) ) < 75.0 
|| FloatAbs( ( (Angles1[0] + 360.0) - Angles2[0]) ) < 75.0 
And do it for each angle you need.

You could probably use a few other mathematical formulas which are a lot easier to use, but hard to understand.





EDIT: Incase you're not too awake when reading this, and doubt if this is true, here's the empirical proof (which I wrote down for my brother, who doubted this ;p)


Code:
Testcases: 5 & 75 (true), 5 & 86 (false), 5 & 352 (true), 5 & 250 (false), 352 & 2 (true), 355 & 75 (false). These have been chosen by my brother as each possible case. (First two are communitive due to the Absolute).

5 & 75:
| 5 - 75 | < 75
= | - 70 | < 75
= 70 < 75
= true

5 & 86:
| 5 - 86 | < 75 = 81 < 75 = false 
OR
| 5 - 341 | < 75 = false 
OR
 |365 - 81| < 75 = false

5 & 352:
| 5 - 352 | < 75 = false 
OR
| 5 - 712 | < 75 = false 
OR
 |365 - 352| < 75 = true

5 & 250:
| 5 - 250 | < 75 = false 
OR
| 5 - 580 | < 75 = false 
OR
 |365 - 250| < 75 = false

352 & 2:
| 352 - 2 | < 75 = false 
OR
| 352 - 362 | < 75 = true

355 & 75:
| 355 - 75 | < 75 = false 
OR
| 355 - 435 | < 75 = false 
OR
| 715 - 75 | < 75 = false
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.

Last edited by Monkeys; 07-28-2010 at 01:17. Reason: Forgot the tagmismatches of 75(.0)
Monkeys is offline
Damizean
SourceMod Donor
Join Date: Mar 2009
Old 07-28-2010 , 13:58   Re: Difference between 2 angle vectors?
Reply With Quote #6

You could do it with a simple dot product of the forward vectors of the angles. This is because the dot product of two normalized vectors is the cosine of the angle between them:
Code:
cos a = v1 · v2
The snippet would be something like this.
PHP Code:
Float:GetDifferenceBetweenAngles(Float:fA[3], Float:fB[3])
{
    
decl Float:fFwdA[3]; GetAngleVectors(fAfFwdANULL_VECTORNULL_VECTOR);
    
decl Float:fFwdB[3]; GetAngleVectors(fBfFwdBNULL_VECTORNULL_VECTOR);
    return 
RadToDeg(ArcCosine(fFwdA[0] * fFwdB[0] + fFwdA[1] * fFwdB[1] + fFwdA[2] * fFwdB[2]));
}

// Example
if (GetDifferenceBetweenAngles(Angles1Angles2) > 70.0)
{
    
// Do stuff
    
...

__________________
Dat annoying guy
Damizean is offline
Send a message via AIM to Damizean Send a message via MSN to Damizean
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 07-28-2010 , 19:21   Re: Difference between 2 angle vectors?
Reply With Quote #7

Wow, thank you both so much. I tried to do something like this before you replied, and failed horribly. You've saved my plugin! +respect
__________________
almcaeobtac is offline
Reply



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode