If you want to use vectors you could try this:
Assume that n is the face normal and d the direction vector. p will be the resulting projection vector.
- make sure that n has a length of 1.
- calculate the dot product of d and n and store it in a variable. I’ll call it t for temp.
- perform this calculation: p = d - ( n • t), where n•t means to multiply every value of n with t. This removes every “part” of d that points into the direction of n. In your third figure n•t would be the vector pointing from the tip of B to the tip of A.
I have used this here in the project function: https://github.com/armory3d/logic_pack/blob/master/Sources/armory/logicnode/LookingAtNode.hx
It might be a ltlle hard to read read, as I made slight adjustments to how the math functions work.