How to find angle of rotation given the source point and x-coordinate of destination point?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Just for the sake of simplicity, assume that the centre of rotation is $(0, 0)$. I know that I can find the destination point $(x', y')$ given angle of rotation $a$ and source point $(x, y)$ using
$$begincases
x' = x cos a - y sin a \
y' = x sin a + y cos a \
endcases$$
However, I want to ask how can I find the angle of rotation $a$ given the source point $(x, y)$ and only the x-coordination of the destination point $x'$? The y-coordinate of destination point $y'$ would be according to the angle of rotation $a$ that we get. I am having trouble trying to solve the above equations for the desired value because we don't have exact value of $y'$. It would be great if someone could help. Thanks.
geometry trigonometry
add a comment |Â
up vote
0
down vote
favorite
Just for the sake of simplicity, assume that the centre of rotation is $(0, 0)$. I know that I can find the destination point $(x', y')$ given angle of rotation $a$ and source point $(x, y)$ using
$$begincases
x' = x cos a - y sin a \
y' = x sin a + y cos a \
endcases$$
However, I want to ask how can I find the angle of rotation $a$ given the source point $(x, y)$ and only the x-coordination of the destination point $x'$? The y-coordinate of destination point $y'$ would be according to the angle of rotation $a$ that we get. I am having trouble trying to solve the above equations for the desired value because we don't have exact value of $y'$. It would be great if someone could help. Thanks.
geometry trigonometry
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Just for the sake of simplicity, assume that the centre of rotation is $(0, 0)$. I know that I can find the destination point $(x', y')$ given angle of rotation $a$ and source point $(x, y)$ using
$$begincases
x' = x cos a - y sin a \
y' = x sin a + y cos a \
endcases$$
However, I want to ask how can I find the angle of rotation $a$ given the source point $(x, y)$ and only the x-coordination of the destination point $x'$? The y-coordinate of destination point $y'$ would be according to the angle of rotation $a$ that we get. I am having trouble trying to solve the above equations for the desired value because we don't have exact value of $y'$. It would be great if someone could help. Thanks.
geometry trigonometry
Just for the sake of simplicity, assume that the centre of rotation is $(0, 0)$. I know that I can find the destination point $(x', y')$ given angle of rotation $a$ and source point $(x, y)$ using
$$begincases
x' = x cos a - y sin a \
y' = x sin a + y cos a \
endcases$$
However, I want to ask how can I find the angle of rotation $a$ given the source point $(x, y)$ and only the x-coordination of the destination point $x'$? The y-coordinate of destination point $y'$ would be according to the angle of rotation $a$ that we get. I am having trouble trying to solve the above equations for the desired value because we don't have exact value of $y'$. It would be great if someone could help. Thanks.
geometry trigonometry
edited Aug 2 at 13:25
asked Aug 2 at 12:58
Newbie
184
184
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
First we replace $sin a$ with $sqrt1-cos^2a$:
$$x' = x cos a - y sqrt1-cos^2 a$$
Then we eliminate the square root by isolating it and squaring:
$$y sqrt1-cos^2 a = x cos a - x'$$
$$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$
This can now be rewritten as a quadric in $cos a$:
$$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
$$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$
It can be solve using the "$p$-$q$-formula":
$$
cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
= fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
$$
A couple of notes:
- The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.
- When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.
Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
â Newbie
Aug 2 at 16:00
Oh, you are right.
â md2perpe
Aug 2 at 16:03
add a comment |Â
up vote
2
down vote
Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if youâÂÂre coding this, thereâÂÂs likely a two-argument form of the arctangent function available (often called something like ATAN2
) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.
This is the approach I would have taken. Plus one.
â Lubin
Aug 2 at 22:36
Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
â Newbie
Aug 3 at 1:22
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
First we replace $sin a$ with $sqrt1-cos^2a$:
$$x' = x cos a - y sqrt1-cos^2 a$$
Then we eliminate the square root by isolating it and squaring:
$$y sqrt1-cos^2 a = x cos a - x'$$
$$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$
This can now be rewritten as a quadric in $cos a$:
$$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
$$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$
It can be solve using the "$p$-$q$-formula":
$$
cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
= fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
$$
A couple of notes:
- The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.
- When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.
Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
â Newbie
Aug 2 at 16:00
Oh, you are right.
â md2perpe
Aug 2 at 16:03
add a comment |Â
up vote
1
down vote
accepted
First we replace $sin a$ with $sqrt1-cos^2a$:
$$x' = x cos a - y sqrt1-cos^2 a$$
Then we eliminate the square root by isolating it and squaring:
$$y sqrt1-cos^2 a = x cos a - x'$$
$$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$
This can now be rewritten as a quadric in $cos a$:
$$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
$$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$
It can be solve using the "$p$-$q$-formula":
$$
cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
= fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
$$
A couple of notes:
- The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.
- When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.
Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
â Newbie
Aug 2 at 16:00
Oh, you are right.
â md2perpe
Aug 2 at 16:03
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
First we replace $sin a$ with $sqrt1-cos^2a$:
$$x' = x cos a - y sqrt1-cos^2 a$$
Then we eliminate the square root by isolating it and squaring:
$$y sqrt1-cos^2 a = x cos a - x'$$
$$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$
This can now be rewritten as a quadric in $cos a$:
$$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
$$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$
It can be solve using the "$p$-$q$-formula":
$$
cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
= fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
$$
A couple of notes:
- The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.
- When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.
First we replace $sin a$ with $sqrt1-cos^2a$:
$$x' = x cos a - y sqrt1-cos^2 a$$
Then we eliminate the square root by isolating it and squaring:
$$y sqrt1-cos^2 a = x cos a - x'$$
$$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$
This can now be rewritten as a quadric in $cos a$:
$$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
$$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$
It can be solve using the "$p$-$q$-formula":
$$
cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
= fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
$$
A couple of notes:
- The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.
- When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.
answered Aug 2 at 13:46
md2perpe
5,6191921
5,6191921
Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
â Newbie
Aug 2 at 16:00
Oh, you are right.
â md2perpe
Aug 2 at 16:03
add a comment |Â
Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
â Newbie
Aug 2 at 16:00
Oh, you are right.
â md2perpe
Aug 2 at 16:03
Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
â Newbie
Aug 2 at 16:00
Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
â Newbie
Aug 2 at 16:00
Oh, you are right.
â md2perpe
Aug 2 at 16:03
Oh, you are right.
â md2perpe
Aug 2 at 16:03
add a comment |Â
up vote
2
down vote
Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if youâÂÂre coding this, thereâÂÂs likely a two-argument form of the arctangent function available (often called something like ATAN2
) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.
This is the approach I would have taken. Plus one.
â Lubin
Aug 2 at 22:36
Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
â Newbie
Aug 3 at 1:22
add a comment |Â
up vote
2
down vote
Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if youâÂÂre coding this, thereâÂÂs likely a two-argument form of the arctangent function available (often called something like ATAN2
) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.
This is the approach I would have taken. Plus one.
â Lubin
Aug 2 at 22:36
Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
â Newbie
Aug 3 at 1:22
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if youâÂÂre coding this, thereâÂÂs likely a two-argument form of the arctangent function available (often called something like ATAN2
) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.
Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if youâÂÂre coding this, thereâÂÂs likely a two-argument form of the arctangent function available (often called something like ATAN2
) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.
edited Aug 3 at 1:23
answered Aug 2 at 21:23
amd
25.7k2943
25.7k2943
This is the approach I would have taken. Plus one.
â Lubin
Aug 2 at 22:36
Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
â Newbie
Aug 3 at 1:22
add a comment |Â
This is the approach I would have taken. Plus one.
â Lubin
Aug 2 at 22:36
Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
â Newbie
Aug 3 at 1:22
This is the approach I would have taken. Plus one.
â Lubin
Aug 2 at 22:36
This is the approach I would have taken. Plus one.
â Lubin
Aug 2 at 22:36
Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
â Newbie
Aug 3 at 1:22
Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
â Newbie
Aug 3 at 1:22
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2870039%2fhow-to-find-angle-of-rotation-given-the-source-point-and-x-coordinate-of-destina%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password