0

I'M reading the book "Beginning Game Development with Python and Pygame". The book showed me how to calculate the distance between two points using vectors. It first explained that you just subtract the values in the first point from the second. But just page or two pages later it says that in order to calculate the distance I need to get the square root of x squared + y squared. math.sqrt(self.x**2 + self.y**2)
The book seem to be describing the same thing in two completely different ways. Could someone please clarify this for me? Thanks.

3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by Beat_Slayer
0

Let's say we have a line from origin (0,0) to point (10,0) and another line to (0,10), intuitively they are equal length and actually when the lines are horizontal and vertical you can only substract the differing values: 10-0 = 10.

But you can also in this case to use the longer formula: ((10-0)**2-(0-0)**2)**0.5=(10**2)**0.5 = 10.

0

The distance between vectors, presuming you have vector A and B with two coordinates x and y, is:

sqrt(((Ax - Bx) ** 2) + ((Ay - By) ** 2))
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.