Solving 3D Vectors Physics Programming Question

  • Thread starter Thread starter volta7
  • Start date Start date
  • Tags Tags
    3d C++ Vectors
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 1K views
volta7
Messages
1
Reaction score
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
 
Physics news on Phys.org
It would probably be easier to take the two positions (man and sweet dish) and form a unit vector pointing from the man to the dish. Then form a unit vector from the man's facing direction vector. Compare them.

That the man's position is important should be clear. Make a sketch. Keeping the same facing direction vector, move the man about the room and see if he ever faces the sweet dish depending upon his location.