Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if vectors are facing same direction

I am working on a question where I am working within a right-handed coordinate system where the y-axis is straight up. I am supplied a structure that represents a 3-dimensional vector that looks like this:

struct vec{float x; float y; float z; };

I need to write a function that takes in a unit vector representing north and a unit vector represent a player's forward vector, and return if they are facing more north than south. Unfortunatly I have no idea where to go from here, I believe I have to do something like:

PlayerDirection = sqrt((PlayerVector.x *= PlayerVector.x)
                     + (PlayerVector.y *= PlayerVector.y)
                     + (PlayerVector.z *= PlayerVector.z));

But I do not know where to go from here. Any help/explanation would help, thanks.

like image 418
user9564128 Avatar asked Oct 19 '25 13:10

user9564128


1 Answers

apply a dot product to both vectors. The dot product will be positive if the angle between both vectors is smaller than 90 degrees, and negative otherwise.

like image 194
RAM Avatar answered Oct 21 '25 03:10

RAM