This was my original working before Xavier pointed out the inconsistencies. (back to main page)
Alternative using Matrix representation
perpendicular component
A B =
(A B) * B/B^{2}
A B can be calculated as follows:
x = Ay * Bz  By * Az
y = Az * Bx  Bz * Ax
z = Ax * By  Bx * Ay
So,
(A B)x
= ((Az * Bx  Bz * Ax) * Bz  By * (Ax * By  Bx * Ay)) / (Bx^{2} +
By^{2} + Bz^{2})
(A B)y
= ((Ax * By  Bx * Ay) * Bx  Bz * (Ay * Bz  By * Az)) / (Bx^{2} +
By^{2} + Bz^{2})
(A B)z
= ((Ay * Bz  By * Az) * By  Bx * (Az * Bx  Bz * Ax)) / (Bx^{2} +
By^{2} + Bz^{2})
grouping terms,
(A B)x
= (Az * Bx* Bz  Bz * Ax* Bz  Ax * By* By + Bx * Ay* By) / (Bx^{2}
+ By^{2} + Bz^{2})
(A B)y
= (Ax * By* Bx  Bx * Ay* Bx  Ay * Bz*Bz + By * Az*Bz) / (Bx^{2} +
By^{2} + Bz^{2})
(A B)z
= (Ay * Bz* By  By * Az* By  Az * Bx*Bx + Bz * Ax*Bx) / (Bx^{2} +
By^{2} + Bz^{2})
In matrix form,
(A
B) = 1 / (Bx^{2} + By^{2} + Bz^{2})* 
Bz* Bz By* By 
Bx * By 
Bx* Bz 
By* Bx 
Bx*Bx Bz*Bz 
By *Bz 
Bz *Bx 
Bz* By 
By*By Bx*Bx 

[A] 
I think the signs of all terms should be inverted, see error heading below,
can anyone help?
Alternative Form
As pointed out here, If B is normalised (unit
length) then Bx^{2} + By^{2} + Bz^{2} =1 so we
get:
(A
B) = 
Bx*Bx  1 
Bx * By 
Bx* Bz 
By* Bx 
By*By 1 
By *Bz 
Bz *Bx 
Bz* By 
Bz*Bz  1 

[A] 
which is:
(A
B) = ( 

* 

[I])[A] 
which is:
(A
B) = (B * B^{t}  [I]) [A]
where:
 [I] = unit matrix
 B^{t} = transpose of B vector
As this is quite a simple equation I wonder if there is a simpler way
to derive it? perhaps the method of least squares discussed
here. 
parallel component
A  P = A • P * P/B^{2}
A • P can be calculated as follows:
Ax * Bx + Ay * By + Az * Bz
so,
(A  P)x = (Ax * Bx + Ay * By + Az * Bz) * Bx / (Bx^{2} + By^{2}
+ Bz^{2})
(A  P)y = (Ax * Bx + Ay * By + Az * Bz) * By/ (Bx^{2} + By^{2}
+ Bz^{2})
(A  P)z = (Ax * Bx + Ay * By + Az * Bz) * Bz/ (Bx^{2} + By^{2}
+ Bz^{2})
in matrix form this is:
(A  P) = 1 / (Bx^{2} + By^{2} + Bz^{2})* 
Bx^{2} 
Bx * By 
Bx * Bz 
By * Bx 
By^{2} 
By * Bz 
Bz * Bx 
Bz * By 
Bz^{2} 

[A] 
Alternative Form
If B is normalised (unit length) then Bx^{2} + By^{2}
+ Bz^{2} =1 so we get:
(A  P) = 
Bx * Bx 
Bx * By 
Bx * Bz 
By * Bx 
By * By 
By * Bz 
Bz * Bx 
Bz * By 
Bz * Bz 

[A] 
which is:
(A
P) = ( 

* 

)[A] 
which is:
(A
P) = (B * B^{t}) [A]
where:
 B^{t} = transpose of B vector
As this is quite a simple equation I wonder if there is a simpler way
to derive it? perhaps the method of least squares discussed
here. 
Error
we have shown above that:
A = A  B + A B
which would give:
A = (B * B^{t}  [I] + B * B^{t})[A]
which should simplify to A = [I][A] but it does not so it looks like the sign
of (A
B) is inverted can anyone see where I went wrong?
This site may have errors. Don't use for critical systems.