bang | R Documentation |
Calculates the angle between two 2D normalized vectors using dot and cross product
bang(x1, y1, x2, y2)
x1 |
x coordinate of first normalized vector |
y1 |
y coordinate of first normalized vector |
x2 |
x coordinate of second normalized vector |
y2 |
y coordinate of second normalized vector |
The sign of angle is determined by the sign of the cross product of the two vectors.
angle in radians
Vectors must be normalized prior to calling this routine. Used mainly for vectors on the unit sphere.
Jonathan M. Lees <jonathan.lees@unc.edu>
v1 = c(5,3)
v2 = c(6,1)
a1 = c(5,3)/sqrt(v1[1]^2+v1[2]^2)
a2 = c(6,1)/sqrt(v2[1]^2+v2[2]^2)
plot(c(0, v1[1],v2[1] ) , c(0, v1[2],v2[2]), type='n', xlab="x", ylab="y" )
text(c(v1[1],v2[1]) , c(v1[2],v2[2]), labels=c("v1", "v2"), pos=3, xpd=TRUE)
arrows(0, 0, c(v1[1],v2[1] ), c(v1[2],v2[2]))
B = 180*bang(a1[1], a1[2], a2[1], a2[2])/pi
title(paste(sep=" ", "Angle from V1 to V2=",format(B, digits=2)) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.