Featured Posts

8. Bump Mapping in GLSL8. Bump Mapping in GLSL Introduction Bump mapping is essential in todays computer games, and computer graphics in general. Would you like to know the best thing about it? It is extremely simple to implement. Bump mapping works...

Read more

Swiftless GLSL Shader DeveloperSwiftless GLSL Shader Developer Swiftless GLSL Shader Developer   Version 0.1a Currently Swiftless GLSL Shader Developer is in it's first public release, and is currently in alpha status, meaning it is not complete and may contain...

Read more

Wordpress Optimization Wordpress Website Optimizations Introduction Wordpress itself is a fairly wonderful tool. Since switching to it, I find it is a lot quicker to make changes to my website and it is also quicker to get...

Read more

36. OpenGL Framebuffers36. OpenGL Framebuffers Introduction Frame buffers are one of those mythical things that we have all heard of, but many beginner OpenGL developers avoid because there is not much information about them, and they can be confusing...

Read more

1. Terrain Class1. Terrain Class Terrain is one of those things that so far, hasn't been perfectly recreated in computer graphics. But it is almost there! Looking over a beautiful landscape can be one of the most amazing feelings in the...

Read more

  • Prev
  • Next

2. Maths Pythagoras Theorem

Posted on : 25-03-2010 | By : Swiftless | In : Maths

Tags: , , ,

2

Most people who have done maths in high school, would have heard of Pythagoras theorem.

This is used to work out the unknown side of a triangle, if you know the other 2 sides.

Pythagoras Triangle

Here you can see the sides, A, B and C.

Now Pythagoras theorem states that A^2 + B^2 = C^2

So if you know any two sides, you add them in, rearrange the formula if needed, and then you can solve for the unkown sides.

So how would you use this in a game? What about collision detection? Using this you can find quite easily in a 2 dimensional plane when 2 points will meet.

They will meet when A^2 + B^2 = 0

Quite simple really, you take the position of A and B on the X axis and do the equation, then if it comes up with an answer of 0, you then take the position of A and B on the Y axis, then if that also comes to 0, they must be colliding.

So to put that in other words, we are finding the distance :-) If the distance is nothing, then they are located in the same position.

Not sure if that is right, sounds right from my position, although it is 1:18 am.

If you have any questions, please email me at swiftless@gmail.com

VN:F [1.9.3_1094]
Please rate so I know where to improve the site. 1 means needs a lot of improvement, 10 means perfect. If you leave a low rating, please state why. I don't want people just coming to bash the site.
Rating: 7.0/10 (1 vote cast)
VN:F [1.9.3_1094]
Rating: +1 (from 1 vote)
2. Maths Pythagoras Theorem, 7.0 out of 10 based on 1 rating

Related posts:

  1. 1. Maths Distance Formula
  2. 3. Maths Lines
  3. 6. Maths Trigonometry
  4. 4. Maths Vector Length
  5. 7. Maths Radians

Comments (2)

Hi Flekken,

That is exactly true, A^2 + B^2 will only equal 0 if A and B is 0.

While the formula you have given is the true formula for working out the distance between two points, look at what it is actually doing. I will look at 2D space:

Now if we have a collision when the result is 0, if we apply some basic maths to the distance formula, we can remove the sqrt:
0 = sqrt((x2-x1)^2 + (y2-y1)^2)
0^2 = sqrt((x2 – x1)^2 + (y2 – y1)^2)^2
0 = (x2 – x1)^2 + (y2 – y1)^2

And now look at what x2-x1 and y2-y1 do. They give us the length of the line segments A and B.

Therefore:
x2 – x1 = A and y2 – y1 = B
And then:
0 = (A)^2 + (B)^2
0 = A^2 + B^2

Therefore we have a collision. Both this shorthand version and the full version of the distance formula are the same thing.

Hope this helps clarify :)
Swiftless

VN:F [1.9.3_1094]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

I don’t understand how can you use this for calculating distance. The only time A^2 + B^2 would be 0 is when A and B is 0. The proper formula for calculating distance between 2 point is:
sqrt( (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2 )

VA:F [1.9.3_1094]
Rating: 0.0/5 (0 votes cast)
VA:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Write a comment

Improve the web with Nofollow Reciprocity.