acos2

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Analytical Geometry
Introduced first in SolidGeometry 4.5, Creation date: 2019-02-16, Last change: 2025-09-14

2D fnct: returns the angle between two vectors including sign

Description

may be not the first implementation - works only in 2D
Similar to atan2, this function returns angles between -pi .. + pi
in contrast to acos, acos2 return for two vectors or vector list with 2 Coordinates
the angle difference but uses a sign to show right hand (pos) or left hand (neg)

See Also: diffangle

Example Illustration

 missing image of acos2(NL1,NL2,normfirst)

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

Output Results

Algorithm Steps

  1. Check if the vectors in NL1 have two elements. If not, an error is raised.
  2. Determine if the vectors should be normalized based on the normfirst parameter.
  3. If NL2 contains only one vector, replicate it to match the number of vectors in NL1.
  4. If normfirst is true, normalize both NL1 and NL2 using the normr function.
  5. Initialize arrays s, a, and w to store intermediate and final results.
  6. For each pair of vectors in NL1 and NL2:
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