pythagorean theorem to find distance between two points

4 views (last 30 days)
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
madhan ravi on 26 Nov 2018
Read about hypot()
  6 Comments
Walter Roberson
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
madhan ravi on 26 Nov 2018
size(x1) size(x2) size(y1) size(y1) size(A) size(B) ?

Sign in to comment.


Walter Roberson
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
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;

Sign in to comment.

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!