pythagorean theorem to find distance between two points
Show older comments
I am trying to limit the length of an old fashioned Qix video game so that the ball only travels within certain decreased parameters, rather than the full arena, when a specific command is entered in the command line. The full arena is 500, so I was trying to make the decreased arena be 400. I think that I need to use the pythagorean theorem to find the distance between x1 and y1, as well as x2 and y2, and then take that hypotenuse value and decrease it by a particular quantity. I have no idea how to make this happen, and have tried so many things that all result in errors. Please help!
Answers (2)
madhan ravi
on 26 Nov 2018
0 votes
Read about hypot()
6 Comments
jat
on 26 Nov 2018
Walter Roberson
on 26 Nov 2018
What error did you encounter?
jat
on 26 Nov 2018
madhan ravi
on 26 Nov 2018
so see sir Walter's answer below
Walter Roberson
on 26 Nov 2018
At the moment we do not know that you have defined A and B or what you defined them as and how they relate to x1, x2, y1, y2 .
madhan ravi
on 26 Nov 2018
size(x1) size(x2) size(y1) size(y1) size(A) size(B) ?
Walter Roberson
on 26 Nov 2018
[theta, r] = pol2cart(x2-x1, y2-y1);
[newrelx, newrely] = cart2pol(theta, r * reduction_factor);
new_x2 = x1 + newrelx; new_y2 = y1 + newrely;
1 Comment
Walter Roberson
on 26 Nov 2018
By the way, this can be programmed more directly:
new_x2 = x1 + (x2 - x1) * reduction_factor;
new_y2 = y1 + (y2 - y1) * reduction_factor;
Categories
Find more on Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!