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

5. Maths Vector Dot Product

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

Tags: , , , ,

0

Here we are going to be looking at the infamous dot product AKA scalar product.

Dot products are used in computer programming to work out normals for 3d objects. A normal is a vector, perpendicular to the plane it is on.

I couldn’t really find a meaning to what the dot product actually is. So I am going to class it as a means of finding an angle or a length of a vector.

Now there are 3 main ways for writing a dot product equation.

a.b = a1b1 + a2b2 = |a| |b| cos @

Where a.b = [a1, b1] . [a2, b2]

a.b = a1 * b1 + a2 * b2

Which comes out the same as our second formula. While our third formula takes the length of a times by the length of b times by the cosine of theta where theta is the angle between vectors a and b.

Now if the angle between a and b is equal to 90 then a is perpendicular to b.

And that is all there really is to the infamous dot product. It is a rather simple concept really.

So lets have a little play with that. Say we have the points:

AB = [4, -2]

BC = [-1, -2]

And we want to find out if AB is perpendicular to BC. We now have to do the dot product. We cannot use the third method as we don’t know any angles, although we could work them out, but I will explain that in a different topic. As the third equation is simply ‘plug n play’, whack in the numbers and press the calculate button on your calculator.

So to find the dot product we get:

AB . BC

AB . BC = (4 * -1) + (-2 * -2)

AB . BC = -4 + 4

AB . BC = 0

Therefore AB is perpendicular to BC.

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: 8.0/10 (2 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

4. Maths Vector Length

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

Tags: , , ,

1

The first thing we will look at is how to work out the length of a vector.

Vector Length 1

Take a look at the diagram and try to grasp that we can determine the length of every vector there.

————————Figure 1 – The triangle on the left———————-

First go to the iamge in the left. You will see a triangle with sides of length a, b and c.

The vector a is facing towards c, the vector b is facing towards a and the vector c is facing towards b.

So to work out the length of the vectors we start at the end of the vector WITHOUT the arrow and work our way around to the end with the arrow.

To work out the length of a, we would start at the end of a, so the start of b and work around to the end of a with the arrow. So our length would be:

a = -b + -c

Which comes down to:

a = -b-c

If we were to work out negative a, we would get:

-a = c + b

Because to work out the negative value, we start at the other end.

For our formulae for a to be:

a = -b-c

You have to take into account that moving in the same direction is positive and moving opposite to the arrow is negative.

So all our lengths for our triangle would be:

a = -b-c

b = -c-a

c = -a-b

————————Figure 2 – The square on the right———————-

Vector Length 2

If you follow our rules from above, the lengths of our vectors come out to:

a = -d-c+b

b = c+d+a

c = b-a-d

d = -c+b-a

Keep in mind that no matter what shape you have, you ALWAYS work it out the same way. And thanks to vectors being what they are, this will always work.

__LENGTH OF A VECTOR PART 2__

In this part, we are going to be looking at the length of a vector in almost the exact same way as before. Only this time, the characters, a,b and c are not lines, but points.

Vector Length 3

To work out the length of these, you just have to work it out a little differently.

Take point A and point C. Now the length of that vector is AC (with a line above it)

Vector Length 4

The arrow above it just represents a vector instead of a normal line.

So in this diagram we have lengths:

AC

CB

BA

And to work that out is exactly the same as before.

AC = |AC| or -|AB|-|BC|

Where the lines | | represent the length.

__LENGTH OF A VECTOR PART 3__

Here we are going to be acctually calculating the length of the vector using numbers.

Vector Length 5

A is going to be located at (1,1)

B is going to be located at (1,0)

C is going to be located at (2,0.5)

Now the line AC comes to:

AC = [cX - aX, cY - aY]

Therefore:

AC = [2 - 1, 0.5 - 1]

AC = [1, -0.5]

Now to work out the length/distance:

d = sqrt(x^2 + y^2)

And vectors dont acctually have a length measuring system like cm, m, km etc. They are just measured in units.

so AC = sqrt(1^2 + (-0.55)^2)

AC = sqrt(1 + 0.25)

AC = sqrt(1.25) units.

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: 1.0/10 (1 vote cast)
VN:F [1.9.3_1094]
Rating: -1 (from 1 vote)
Improve the web with Nofollow Reciprocity.