- #1
volta7
- 1
- 0
Homework Statement
A man is standing in his home , his position his facing direction and the position of the sweet dish are given ,if he faces the sweet dish , he eats it .
Translating it into CS programming question : write a function ->
bool IsManInFrontofDish( vector3& manPosition, vector3& manFacingPos, vector3& dishPos )
which return true when the man faces the dish;
The programming part is easy , I was worried about the physics part .
Is the manPosition really important in this , or is it just to deceive?
I am attempting a physics programming question for the first time...
Homework Equations
A.B = ||A||.||B||
The Attempt at a Solution
the angle between 2 vectors is 0 if they are in the same direction so simply by replacing manFacingPos with A and
dishPos with B and checking the equation i will be able to get the answer:
translating it into program if it helps :
bool IsManInFrontofDish( vector3& manPosition, vector3& manFacingPos, vector3& dishPos ) {
int magnitude1 = sqrt( dot(manFacingPos, manFacingPos) ); //square root of dot product
int magnitude2 = sqrt( dot(dishPos,dishPos) );
if(dot(manFacingPos, dishPos) == magnitude1*magnitude2) return true;
else return false;
}
P.S. I am not attending any university or school right now , so this is not a homework question