|
-
Senior Member
Got minimum angle between 2 vectors, but need direction as well...
I know I should be able to find this in google, but my google fu is failing, HARD.
So, the magic of dotproduct can get an angle between two vectors really easily (using points here just for simplicity), I managed to find that much on google. I don't think I need to bother with a full vector class, I am only using this stuff sparingly right now.
Actionscript Code:
p2pang = function (p1:Point, p2:Point, inradians) { if (inradians==undefined){inradians = false;} var cosA:Number = p2pdot(p1, p2) / (p1.length * p2.length); var A : Number = Math.acos( cosA ); if ( inradians == false ) {A = A / Math.PI * 180;} return A; } p2pdot = function(p1:Point, p2:Point){ return ( p1.x * p2.x + p1.y * p2.y ); }
So great, works nice, no awkward problems with -180/180 issues, but I want to be able to know which vector is to which side of which. Basically, what rotation do I have to apply to p1 to get to p2. I need the +/- for what I am doing. The above just returns an always positive value.
Is there an easy way to add this to the function above?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|