Syntax
[w,a]=acos2(NL1,NL2,[normfirst])
Input Parameter
NL1 : | | Vector list 1 |
NL2 : | | Vector list 1 |
normfirst : | | default is true; |
Output Parameter
w : | | result from -pi .. + pi |
a : | | area between both vectors |
Examples
a1=acos([0 1]*[1 0]'), a2=acos([1 0]*[0 01]'), acos2([0 1],[1 0]), acos2([1 0],[0 1])
tic; acos2(rand(10,2),rand(10,2)), toc
Copyright 2019-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, acos2
, calculates the signed angle between two 2D vectors or lists of vectors. It is designed to work only in 2D and returns angles between -À and +À, unlike the standard acos
function.
Input Parameters
- NL1: A list of vectors, where each vector is represented as a row with two elements.
- NL2: Another list of vectors, similar to NL1. If NL2 contains only one vector, it is replicated to match the number of vectors in NL1.
- normfirst: An optional boolean parameter (default is true). If true, the vectors are normalized before processing.
Output Results
- w: The signed angle between the vectors in radians, ranging from -À to +À.
- a: The area between the vectors, calculated using the cross product in 2D.
Algorithm Steps
- Check if the vectors in NL1 have two elements. If not, an error is raised.
- Determine if the vectors should be normalized based on the
normfirst
parameter.
- If NL2 contains only one vector, replicate it to match the number of vectors in NL1.
- If
normfirst
is true, normalize both NL1 and NL2 using the normr
function.
- Initialize arrays
s
, a
, and w
to store intermediate and final results.
- For each pair of vectors in NL1 and NL2:
- Calculate the cross product in 2D using the
crossz
function to determine the area and sign.
- If the sign is not zero, calculate the angle using
acos
and multiply by the sign to determine the direction (right-hand or left-hand).
- If the sign is zero, calculate the angle using
acos
without modification.
- Round the result to seven decimal places for precision.
Algorithm explaination created using ChatGPT on 2025-08-19 08:19. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21