Solving 3D Vectors Physics Programming Question

  • Thread starter Thread starter volta7
  • Start date Start date
  • Tags Tags
    3d C++ Vectors
AI Thread Summary
The discussion revolves around determining whether a man is facing a sweet dish using 3D vector physics in programming. The function proposed, IsManInFrontofDish, checks if the angle between the man's facing direction and the dish's position is zero, indicating he is facing the dish. The importance of the man's position is emphasized, as it affects whether he can actually face the dish depending on his location in the room. A suggestion is made to create unit vectors from the man to the dish and from the man's facing direction for comparison. Visualizing the scenario with a sketch is recommended to better understand the relationship between the man's position and the dish.
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.
 

Similar threads

Back
Top