How to project a vector onto an orthonormal basis

An orthonormal basis makes projection easier because the basis vectors are perpendicular and each has length 1. A dot product gives the component along each basis vector directly. We can add those components to get the projection onto their span.

Use one dot product for each basis direction

p=(x·q1)q1+(x·q2)q2

For an orthonormal basis with more vectors, continue the sum. If the basis vectors are the columns of Q, the same formula is p=QQTx.

Find the two coefficients

Use q1=12(1,0,-1) and q2=(12,22,12). Their lengths are 1 and their dot product is zero. For x=(5,6,-1),

x·q1=32x·q2=2+32

Combine the two components

Multiply each coefficient by its basis vector and add component by component. The projection has components

p1=4+322p2=3+2p3=-2+322

The projection lies in the plane spanned by the two basis vectors. The part left over is perpendicular to both of them.