![determine angle vector 2d determine angle vector 2d](https://i.stack.imgur.com/moTpz.png)
The only means to circumvent these problems is to use higher precision for the intermediate calculations, see e.g. The norms of the individual vectors as well as their product are much less error prone. The inaccuracy grows with both the dimension and the length of the vectors involved. The reason for the inaccurate values is that catastrophic cancellation occurs when summing up the terms in the dot product near 0 deg and in the vector product near 90 deg, resp. Imho, just the opposite is true: it fails for angles close to zero and close to pi/2 as well. Unfortunately, we disagree on your conclusion that the ratio of the two different products of vectors yields accurate results. The screen shot below shows examples of each of these options. Angles are returned in radians by default, or degrees if the optional fourth argument is set to 1. If the third point is supplied, the function returns the angle at this point. If the third point is omitted the function returns the angle at the origin between the lines to Point 1 and Point 2. Each point must have the same number of dimensions. The input for the new ANG() function is either two or three points, each of which are defined by a row of 2 or 3 values for 2D or 3D lines.
#DETERMINE ANGLE VECTOR 2D FULL#
The revised spreadsheet can be downloaded from the link above, including full open-source code. I have added a new User Defined Function (UDF) to the VectorFunc.xlsb spreadsheet, which was described in Dots and Crosses. Which is accurate for all angles, and since the (| a || b |) values cancel out the computation time is similar to the other expressions. Has similar problems with angles close to 90 degrees, but combining the two gives: A similar formula using the sine of the angle: Unfortunately this gives poor accuracy for angles close to zero for instance an angle of 1.00E-7 radians evaluates with an error exceeding 1%, and 1.00E-8 radians evaluates as zero. In 3D it is not so obvious, but it can be shown (using the Cosine Rule) that the angle θ between two vectors a and b is given by:
![determine angle vector 2d determine angle vector 2d](http://image.slideserve.com/376379/slide24-l.jpg)
Finding the angle between two lines in 2D is easy, just find the angle of each line with the x-axis from the slope of the line and take the difference.