Developers Web home

How to calculate the angle between two 3D vectors

Calculate the angle between two intersecting unit vectors

If we wish to find the angle created by 3 points P, Q and S we must derived the unit vectors PQ and RS

    Qx - Px  
PQ =    Qy - Py  
    Qz - Pz  

    Sx - Px  
PS =    Sy - Py  
    Sz - Pz  
Convert to unit vectors:

PQ length, PQl = √( PQx2 + PQy2 + PQz2 )

    PQx / PQl  
Convert PQ to a unit vector =    PQy / PQl  
    PQz / PQl  

PS length, PSl = √( PSx2 + PSy2 + PSz2 )

    PSx / PSl  
Convert PS to a unit vector =    PSy / PSl  
    PSz / PSl  

Now we have the 2 unit vectors PQ and PS.

The angle α between PQ and PS:

α = cos-1(PQ.PS)

PQ.PS = ( PQx × PSx ) + ( PQy × PSy ) + ( PQz × PSz )

∴ α = cos-1( ( PQx × PSx ) + ( PQy × PSy ) + ( PQz × PSz ) )

No conversation on this topic You must be logged in to add to the conversation