[R] vector normal to a plane
Thomas Lumley
tlumley at u.washington.edu
Fri May 28 23:55:48 CEST 2004
W is looking for the vector cross product (a specifically
three-dimensional object important in physics and engineering). The
crossproduct() function provides a matrix product so that crossprod(x,y)
is t(x)%*%y, something completely different.
For the three-dimensional case you could define the cross and dot products
"%x%"<-function(a,b) {c(a[2]*b[3]-a[3]*b[2], -a[1]*b[3]+a[3]*b[1],
a[1]*b[2]-a[2]*b[1])}
"%.%%<-function(a,b) sum(a*b)
It would make sense, of course, to check that the arguments actually were
vectors of length 3.
-thomas
More information about the R-help
mailing list