## signedAngleTwoVecto​rs

Version 3.0 (3.11 KB) by
Returns signed angle between two 3-D vectors in plane spanning them with direction determined either by the right hand rule or specification

Updated 2 Jul 2021

Calculate the angle (in radians) between two three-D vectors defined as the angle from startVec to endVec in the plane defined by its normal vector being either the cross product or negation of startVec x endVec. Pass 1 for 'oneCaseFlag' if you are not passing matrices of row vectors.
Usage details for the 'rotateVec' argument are as follows: rotateVec is a user-specified (normal) vector pointing from the side of the plane that startVec and endVec lie in, which points in the direction about which the angle is measured. If you do not know what this normal vector is, then pass an empty vector and the function will substitute their cross product, but in this case the angles will always be positive, so the user must employ some other test external to the function to determine when the angle should be positive or negative based on the directions of input vectors startVec and endVec, and adjust accordingly.
For derivation of the implemented formulas, see StackOverflow answer at:
https://stackoverflow.com/a/33920320/12763497 or search for the term "signed angle between two 3D vectors with the same origin within the same plane" in the search bar and look for the 2015 answer by Adrian Leonhard. That proof is the basis of the corresponding post in math.stackexchange:
https://math.stackexchange.com/a/3759166/747468, which explains how to calculate the four-quadrant arctangent based on Adrian Leonhard's proof.

### Cite As

Seth Wagenman (2023). signedAngleTwoVectors (https://www.mathworks.com/matlabcentral/fileexchange/78300-signedangletwovectors), MATLAB Central File Exchange. Retrieved .

##### MATLAB Release Compatibility
Created with R2019b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
3.0

Had order of arguments to atan2 backwards! Also included unit3DNonZeroVectorByRow function and updated instances of oneCaseFlat to oneVecFlag per suggestion.

2.0

Found logic error in sign check; fixed to be row-wise

1.2.0

Cleaned up code a bit and used unit3DNonZeroVectorByRow instead of prior version of that function by same author.

1.1.2

Changed name of file and function to make 3-D explicit.

1.1.1

Got rid of bug when computing dot products of single vectors (rather than matrices of row vectors) as input arguments.

1.1.0

Made code cleaner and variable names more meaningful

1.0.2

debugged check for coplanarity of rotateVec with startVec, endVec

1.0.1

changed last line to calculate beta (returned object) rather than theta

1.0.0