finding angle between one point and another point with ray

Multi tool use
Multi tool use












0












$begingroup$


I'm trying to figure out the angle between the direction to an objective point relative to a player looking a certain direction.



This will be used in making a direction indicator for a game.



Here's a diagram made in Geogebra that shows the scenario



enter image description here



Updated diagram to avoid confusion



I have X,Y coordinates of the player and objective and I have the rotation of the player to work with.










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    do you know about the dot/scalar product in basic vector mathematics?
    $endgroup$
    – danimal
    Aug 23 '16 at 16:11










  • $begingroup$
    I've heard of it but never learned much about it
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:15
















0












$begingroup$


I'm trying to figure out the angle between the direction to an objective point relative to a player looking a certain direction.



This will be used in making a direction indicator for a game.



Here's a diagram made in Geogebra that shows the scenario



enter image description here



Updated diagram to avoid confusion



I have X,Y coordinates of the player and objective and I have the rotation of the player to work with.










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    do you know about the dot/scalar product in basic vector mathematics?
    $endgroup$
    – danimal
    Aug 23 '16 at 16:11










  • $begingroup$
    I've heard of it but never learned much about it
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:15














0












0








0





$begingroup$


I'm trying to figure out the angle between the direction to an objective point relative to a player looking a certain direction.



This will be used in making a direction indicator for a game.



Here's a diagram made in Geogebra that shows the scenario



enter image description here



Updated diagram to avoid confusion



I have X,Y coordinates of the player and objective and I have the rotation of the player to work with.










share|cite|improve this question











$endgroup$




I'm trying to figure out the angle between the direction to an objective point relative to a player looking a certain direction.



This will be used in making a direction indicator for a game.



Here's a diagram made in Geogebra that shows the scenario



enter image description here



Updated diagram to avoid confusion



I have X,Y coordinates of the player and objective and I have the rotation of the player to work with.







angle






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 24 '18 at 9:33









Glorfindel

3,41381930




3,41381930










asked Aug 23 '16 at 16:07









puppy333puppy333

32




32








  • 1




    $begingroup$
    do you know about the dot/scalar product in basic vector mathematics?
    $endgroup$
    – danimal
    Aug 23 '16 at 16:11










  • $begingroup$
    I've heard of it but never learned much about it
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:15














  • 1




    $begingroup$
    do you know about the dot/scalar product in basic vector mathematics?
    $endgroup$
    – danimal
    Aug 23 '16 at 16:11










  • $begingroup$
    I've heard of it but never learned much about it
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:15








1




1




$begingroup$
do you know about the dot/scalar product in basic vector mathematics?
$endgroup$
– danimal
Aug 23 '16 at 16:11




$begingroup$
do you know about the dot/scalar product in basic vector mathematics?
$endgroup$
– danimal
Aug 23 '16 at 16:11












$begingroup$
I've heard of it but never learned much about it
$endgroup$
– puppy333
Aug 23 '16 at 16:15




$begingroup$
I've heard of it but never learned much about it
$endgroup$
– puppy333
Aug 23 '16 at 16:15










1 Answer
1






active

oldest

votes


















1












$begingroup$

In two dimensions, you can use the scalar or dot product of two vectors:



$$
mathbf{a}cdot mathbf{b}=left(begin{matrix} a_x \ a_y end{matrix}right)cdotleft(begin{matrix} b_x \ b_y end{matrix}right) = a_xb_x + a_yb_y = |mathbf{a}| |mathbf{b}|costheta
$$



where $theta$ is the angle between the two vectors (and which could be either the acute or obtuse angle, depending on the directions of the vectors).



So, you'll need to find the vectors from



a) the player to the objective and



b) the player to the playerview



To get these vectors, imagine the player has coordinates $(p_x,p_y)$ and the objective has coordinates $(q_x,q_y)$.
The vector from the player to the objective will then be:



$$left(begin{matrix} q_x - p_x \ q_y-p_y end{matrix}right)$$
(You can do the same thing for the playerview if needed)



Then you need to calculate the magnitudes (lengths) of these vectors, and their scalar product via the middle relationship above.
The angle will then be the inverse cosine of the dot product divided by the product of their magnitudes.



Edit:



Instead, if you know the angle for the playerview relative to north, you can use the dot product of the northwards (unit) vector (which is $left(begin{matrix} 0 \ 1 end{matrix}right)$) and the vector above to find the angle from north to the objective, and then add (or subtract as necessary) the two angles to find the overall angle.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    ok so I would need to get the vectors from the player to objective and player to playerview and from that I can find the angle between the direction of the objective and the way the player is looking
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:38










  • $begingroup$
    exactly! :) can you do that?
    $endgroup$
    – danimal
    Aug 23 '16 at 16:44










  • $begingroup$
    I might be making another question >.< I've got the "I know I learned that sometime before but have now forgotten it" problem :P
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:48












  • $begingroup$
    I mean I know I have what I need ( objective location , player location and player rotation.)
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:50










  • $begingroup$
    ok so what information is exactly needed for "a" and "b"
    $endgroup$
    – puppy333
    Aug 23 '16 at 17:05












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1901229%2ffinding-angle-between-one-point-and-another-point-with-ray%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1












$begingroup$

In two dimensions, you can use the scalar or dot product of two vectors:



$$
mathbf{a}cdot mathbf{b}=left(begin{matrix} a_x \ a_y end{matrix}right)cdotleft(begin{matrix} b_x \ b_y end{matrix}right) = a_xb_x + a_yb_y = |mathbf{a}| |mathbf{b}|costheta
$$



where $theta$ is the angle between the two vectors (and which could be either the acute or obtuse angle, depending on the directions of the vectors).



So, you'll need to find the vectors from



a) the player to the objective and



b) the player to the playerview



To get these vectors, imagine the player has coordinates $(p_x,p_y)$ and the objective has coordinates $(q_x,q_y)$.
The vector from the player to the objective will then be:



$$left(begin{matrix} q_x - p_x \ q_y-p_y end{matrix}right)$$
(You can do the same thing for the playerview if needed)



Then you need to calculate the magnitudes (lengths) of these vectors, and their scalar product via the middle relationship above.
The angle will then be the inverse cosine of the dot product divided by the product of their magnitudes.



Edit:



Instead, if you know the angle for the playerview relative to north, you can use the dot product of the northwards (unit) vector (which is $left(begin{matrix} 0 \ 1 end{matrix}right)$) and the vector above to find the angle from north to the objective, and then add (or subtract as necessary) the two angles to find the overall angle.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    ok so I would need to get the vectors from the player to objective and player to playerview and from that I can find the angle between the direction of the objective and the way the player is looking
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:38










  • $begingroup$
    exactly! :) can you do that?
    $endgroup$
    – danimal
    Aug 23 '16 at 16:44










  • $begingroup$
    I might be making another question >.< I've got the "I know I learned that sometime before but have now forgotten it" problem :P
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:48












  • $begingroup$
    I mean I know I have what I need ( objective location , player location and player rotation.)
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:50










  • $begingroup$
    ok so what information is exactly needed for "a" and "b"
    $endgroup$
    – puppy333
    Aug 23 '16 at 17:05
















1












$begingroup$

In two dimensions, you can use the scalar or dot product of two vectors:



$$
mathbf{a}cdot mathbf{b}=left(begin{matrix} a_x \ a_y end{matrix}right)cdotleft(begin{matrix} b_x \ b_y end{matrix}right) = a_xb_x + a_yb_y = |mathbf{a}| |mathbf{b}|costheta
$$



where $theta$ is the angle between the two vectors (and which could be either the acute or obtuse angle, depending on the directions of the vectors).



So, you'll need to find the vectors from



a) the player to the objective and



b) the player to the playerview



To get these vectors, imagine the player has coordinates $(p_x,p_y)$ and the objective has coordinates $(q_x,q_y)$.
The vector from the player to the objective will then be:



$$left(begin{matrix} q_x - p_x \ q_y-p_y end{matrix}right)$$
(You can do the same thing for the playerview if needed)



Then you need to calculate the magnitudes (lengths) of these vectors, and their scalar product via the middle relationship above.
The angle will then be the inverse cosine of the dot product divided by the product of their magnitudes.



Edit:



Instead, if you know the angle for the playerview relative to north, you can use the dot product of the northwards (unit) vector (which is $left(begin{matrix} 0 \ 1 end{matrix}right)$) and the vector above to find the angle from north to the objective, and then add (or subtract as necessary) the two angles to find the overall angle.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    ok so I would need to get the vectors from the player to objective and player to playerview and from that I can find the angle between the direction of the objective and the way the player is looking
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:38










  • $begingroup$
    exactly! :) can you do that?
    $endgroup$
    – danimal
    Aug 23 '16 at 16:44










  • $begingroup$
    I might be making another question >.< I've got the "I know I learned that sometime before but have now forgotten it" problem :P
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:48












  • $begingroup$
    I mean I know I have what I need ( objective location , player location and player rotation.)
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:50










  • $begingroup$
    ok so what information is exactly needed for "a" and "b"
    $endgroup$
    – puppy333
    Aug 23 '16 at 17:05














1












1








1





$begingroup$

In two dimensions, you can use the scalar or dot product of two vectors:



$$
mathbf{a}cdot mathbf{b}=left(begin{matrix} a_x \ a_y end{matrix}right)cdotleft(begin{matrix} b_x \ b_y end{matrix}right) = a_xb_x + a_yb_y = |mathbf{a}| |mathbf{b}|costheta
$$



where $theta$ is the angle between the two vectors (and which could be either the acute or obtuse angle, depending on the directions of the vectors).



So, you'll need to find the vectors from



a) the player to the objective and



b) the player to the playerview



To get these vectors, imagine the player has coordinates $(p_x,p_y)$ and the objective has coordinates $(q_x,q_y)$.
The vector from the player to the objective will then be:



$$left(begin{matrix} q_x - p_x \ q_y-p_y end{matrix}right)$$
(You can do the same thing for the playerview if needed)



Then you need to calculate the magnitudes (lengths) of these vectors, and their scalar product via the middle relationship above.
The angle will then be the inverse cosine of the dot product divided by the product of their magnitudes.



Edit:



Instead, if you know the angle for the playerview relative to north, you can use the dot product of the northwards (unit) vector (which is $left(begin{matrix} 0 \ 1 end{matrix}right)$) and the vector above to find the angle from north to the objective, and then add (or subtract as necessary) the two angles to find the overall angle.






share|cite|improve this answer











$endgroup$



In two dimensions, you can use the scalar or dot product of two vectors:



$$
mathbf{a}cdot mathbf{b}=left(begin{matrix} a_x \ a_y end{matrix}right)cdotleft(begin{matrix} b_x \ b_y end{matrix}right) = a_xb_x + a_yb_y = |mathbf{a}| |mathbf{b}|costheta
$$



where $theta$ is the angle between the two vectors (and which could be either the acute or obtuse angle, depending on the directions of the vectors).



So, you'll need to find the vectors from



a) the player to the objective and



b) the player to the playerview



To get these vectors, imagine the player has coordinates $(p_x,p_y)$ and the objective has coordinates $(q_x,q_y)$.
The vector from the player to the objective will then be:



$$left(begin{matrix} q_x - p_x \ q_y-p_y end{matrix}right)$$
(You can do the same thing for the playerview if needed)



Then you need to calculate the magnitudes (lengths) of these vectors, and their scalar product via the middle relationship above.
The angle will then be the inverse cosine of the dot product divided by the product of their magnitudes.



Edit:



Instead, if you know the angle for the playerview relative to north, you can use the dot product of the northwards (unit) vector (which is $left(begin{matrix} 0 \ 1 end{matrix}right)$) and the vector above to find the angle from north to the objective, and then add (or subtract as necessary) the two angles to find the overall angle.







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Aug 24 '16 at 11:05

























answered Aug 23 '16 at 16:29









danimaldanimal

1,8161612




1,8161612












  • $begingroup$
    ok so I would need to get the vectors from the player to objective and player to playerview and from that I can find the angle between the direction of the objective and the way the player is looking
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:38










  • $begingroup$
    exactly! :) can you do that?
    $endgroup$
    – danimal
    Aug 23 '16 at 16:44










  • $begingroup$
    I might be making another question >.< I've got the "I know I learned that sometime before but have now forgotten it" problem :P
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:48












  • $begingroup$
    I mean I know I have what I need ( objective location , player location and player rotation.)
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:50










  • $begingroup$
    ok so what information is exactly needed for "a" and "b"
    $endgroup$
    – puppy333
    Aug 23 '16 at 17:05


















  • $begingroup$
    ok so I would need to get the vectors from the player to objective and player to playerview and from that I can find the angle between the direction of the objective and the way the player is looking
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:38










  • $begingroup$
    exactly! :) can you do that?
    $endgroup$
    – danimal
    Aug 23 '16 at 16:44










  • $begingroup$
    I might be making another question >.< I've got the "I know I learned that sometime before but have now forgotten it" problem :P
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:48












  • $begingroup$
    I mean I know I have what I need ( objective location , player location and player rotation.)
    $endgroup$
    – puppy333
    Aug 23 '16 at 16:50










  • $begingroup$
    ok so what information is exactly needed for "a" and "b"
    $endgroup$
    – puppy333
    Aug 23 '16 at 17:05
















$begingroup$
ok so I would need to get the vectors from the player to objective and player to playerview and from that I can find the angle between the direction of the objective and the way the player is looking
$endgroup$
– puppy333
Aug 23 '16 at 16:38




$begingroup$
ok so I would need to get the vectors from the player to objective and player to playerview and from that I can find the angle between the direction of the objective and the way the player is looking
$endgroup$
– puppy333
Aug 23 '16 at 16:38












$begingroup$
exactly! :) can you do that?
$endgroup$
– danimal
Aug 23 '16 at 16:44




$begingroup$
exactly! :) can you do that?
$endgroup$
– danimal
Aug 23 '16 at 16:44












$begingroup$
I might be making another question >.< I've got the "I know I learned that sometime before but have now forgotten it" problem :P
$endgroup$
– puppy333
Aug 23 '16 at 16:48






$begingroup$
I might be making another question >.< I've got the "I know I learned that sometime before but have now forgotten it" problem :P
$endgroup$
– puppy333
Aug 23 '16 at 16:48














$begingroup$
I mean I know I have what I need ( objective location , player location and player rotation.)
$endgroup$
– puppy333
Aug 23 '16 at 16:50




$begingroup$
I mean I know I have what I need ( objective location , player location and player rotation.)
$endgroup$
– puppy333
Aug 23 '16 at 16:50












$begingroup$
ok so what information is exactly needed for "a" and "b"
$endgroup$
– puppy333
Aug 23 '16 at 17:05




$begingroup$
ok so what information is exactly needed for "a" and "b"
$endgroup$
– puppy333
Aug 23 '16 at 17:05


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1901229%2ffinding-angle-between-one-point-and-another-point-with-ray%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







LbgQuiONAbtcjxl7qY1GjZdJ,9cgJl1fOqiQE,fiNas,mC4l
e 8Bpw1

Popular posts from this blog

Plaza Victoria

Puebla de Zaragoza

Musa