[R] vector normal to a plane

Gabor Grothendieck ggrothendieck at myway.com
Sat May 29 01:31:32 CEST 2004


Thomas Lumley <tlumley <at> u.washington.edu> writes:

: 
: 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])}


Alternately, you could get the cofactors from solve:

cross3 <- function(a,b) {
	m <- cbind(a,b,1)
	solve(m)[3,]*det(m)
}




More information about the R-help mailing list