webdevRefinery Forum: Quick Explanation of Vectors - webdevRefinery Forum

Jump to content

Think a topic deserves its own subforum?

Any topic that gets popular here will have a subforum made for it, as long as there are folks around who can answer questions! So if you think wdR is missing something, just talk about it here :)
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rate Topic: -----

User is offline Renegade 

  • 418 I'm a teapot
  • Group: Members
  • Posts: 748
  • Joined: 08-March 10
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL,Graphics

Posted 22 May 2012 - 03:29 PM (#1)

Quick Explanation of Vectors


So it took me a long time to grasp the concept of vectors, which in hindsight is silly considering how simple they are when you look at it correctly. So this is a quick explanation of vectors which are critical to any sort of game development or graphics work in general.

What are vectors?
Vectors are quantities which have magnitude and direction. Euclidean Vectors, the common computed type, are essentially right angled triangles which each have a hypotenuse, opposite and adjacent. They are represented with x and y components (and z in 3D space). Let's take an example V(3, 4). Looks like any old geometric point right? That's true however, hidden inside that is direction.

Posted Image

From the above diagram we can see a triangle forming. We can also see that the adjacent i.e. x component is 3 and the opposite i.e. the y component is 4. This is how vectors should be viewed and not as points (which is how I originally interpreted them). From that triangle we can deduce the magnitude and direction of V.

The magnitude or hypotenuse is gotten by Pythagoras which everyone should know to be:
(adjacent)^2 + (opposite)^2 = (hypotenuse)^2


And by heaping the square to the other side, we get the hypotenuse:
sqrt((adjacent)^2 + (opposite)^2)) = hypotenuse
Sqrt(3^2 + 4^2) = hypotenuse
Sqrt(25) = hypotenuse
5 = hypotenuse = magnitude


Posted Image

The direction of the vector is the slope of the hypotenuse which can be gotten using tan:

tan(angle) = opposite/adjacent
tan(angle) = 4/3
Angle = tan^-1(4/3) .. Tan inverse
Angle = 53 degrees


Why is any of this important?
Vectors can represent acceleration, velocity and displacement and any sort of force, which is essential to any physics orientated game. It allows for you to calculate paths, trajectories and basically all aspects of physics within code (maybe a slight exaggeration). Hopefully this short explanation may help your understanding  of vectors. Forgive the poor diagrams, Omnigraffle on the iPad is good but not perfect.
http://adriancooney.ieGithubTwitterDribbbleForrst
We all die. The goal isn't to live forever. The goal is to create something that will.

Array(16).join({}-{}) + " Batman!";
4


User is offline iCyan 

  • Group: Members
  • Posts: 204
  • Joined: 15-May 11
  • Expertise:HTML,CSS,Graphics,Flash

Posted 22 May 2012 - 04:15 PM (#2)

Excellent quick explanation! Physics in games are absolutely crucial, if you want your game physics to look realistic and be believable.

Although I should mention, its not wrong to view them as "points" in relation to graphics since a vector graphics file describes lines as a series of points that need to be connected. Redrawing these points is what causes vector files to be infinitely scalable without losing quality.
iCyan Allias
1


User is offline Hyde 

  • Group: Members
  • Posts: 1562
  • Joined: 08-March 10

Posted 22 May 2012 - 09:21 PM (#3)

Great initiative! +1 for you. :)
Hyde | HTML & CSS | PHP & SQL | Objective-C | Java | Basic JavaScript
0


User is offline TheEmpty 

  • I say words in sequences.
  • Group: Members
  • Posts: 5154
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Python,Ruby on Rails,SQL

Posted 22 May 2012 - 09:22 PM (#4)

And they're extremely easy to add. Although multiplication isn't the same, there is a difference between a x b and a * b. Also you can just add another element to vectors since each one is independent. Then the magnitude just needs to be adjusted to include that new element. Such as adding z or time.

Spoiler

Reserved.
0


User is offline NeilHanlon 

  • Group: Members
  • Posts: 884
  • Joined: 08-July 10
  • LocationRowley, Massachusetts
  • Expertise:HTML,CSS,PHP,Java,Graphics

Posted 22 May 2012 - 10:22 PM (#5)

Vectors are not easy to add.

Well, in physics they aren't. Cause you don't just add them. Net force and all that jazz. >.>
Thanks,
兄ニール

Website | Blog | @NeilHanlon | About.Me | Facebook | LinkedIn
0


User is offline TheEmpty 

  • I say words in sequences.
  • Group: Members
  • Posts: 5154
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Python,Ruby on Rails,SQL

Posted 22 May 2012 - 11:18 PM (#6)

View PostNeilHanlon, on 22 May 2012 - 10:22 PM, said:

Vectors are not easy to add.

Well, in physics they aren't. Cause you don't just add them. Net force and all that jazz. >.>

That's applying forces not adding vectors. Different things. You can add two forces acting on the same object to get their net force. Or you add all the forces together to get the sum force.
Reserved.
0


User is offline NeilHanlon 

  • Group: Members
  • Posts: 884
  • Joined: 08-July 10
  • LocationRowley, Massachusetts
  • Expertise:HTML,CSS,PHP,Java,Graphics

Posted 23 May 2012 - 06:14 AM (#7)

No, I'm talking about adding vectors. In Physics, Force is a vector, as is Work, Velocity, Acceleration, etc.
Thanks,
兄ニール

Website | Blog | @NeilHanlon | About.Me | Facebook | LinkedIn
0


User is online Lemon 

  • I have a dream...
  • Group: Members
  • Posts: 688
  • Joined: 24-February 11
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 23 May 2012 - 06:57 AM (#8)

View PostNeilHanlon, on 23 May 2012 - 06:14 AM, said:

No, I'm talking about adding vectors. In Physics, Force is a vector, as is Work, Velocity, Acceleration, etc.

Depends what form you are given to try to add. Summing polar vectors is nowhere near as neat as adding cartesian vectors, but I still wouldn't classify it as difficult. On the other hand, multiplying polars is far nicer than multiplying cartesians. Regardless though, both forms represent the same conceptual vector, so the statement that vectors are easy to add holds provided you can do the conversion.
Posted Image
In the end, it's not the years in your life that count. It's the life in your years
0


User is offline Sephern 

  • Group: Moderators
  • Posts: 967
  • Joined: 04-June 10
  • LocationReading, UK
  • Expertise:HTML,CSS,PHP,Javascript,Python

Posted 23 May 2012 - 08:10 AM (#9)

They have quite a large role in Computer Graphics too.
0


User is offline TheEmpty 

  • I say words in sequences.
  • Group: Members
  • Posts: 5154
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Python,Ruby on Rails,SQL

Posted 23 May 2012 - 12:31 PM (#10)

View PostNeilHanlon, on 23 May 2012 - 06:14 AM, said:

No, I'm talking about adding vectors. In Physics, Force is a vector, as is Work, Velocity, Acceleration, etc.

Adding vectors is not hard, you break it into components and add.

R_x = A_x + B_x
R_y = A_y + B_y
R_z = A_z + B_z
Reserved.
0


User is offline ianonavy 

  • Group: Members
  • Posts: 685
  • Joined: 14-April 10
  • Expertise:HTML,CSS,Java,Javascript,Python

Posted 23 May 2012 - 12:53 PM (#11)

View PostNeilHanlon, on 23 May 2012 - 06:14 AM, said:

No, I'm talking about adding vectors. In Physics, Force is a vector, as is Work, Velocity, Acceleration, etc.

Actually, Work is energy, so it's a scalar quantity. :P Also, as Rails said, adding vectors is easy. In Linear Algebra, vectors are represented by n x 1 matrices, where n is the number of dimensions. Adding two vectors is as simple as adding the components.
reputation += 1 if post.is_helpful else 0
0


User is online callumacrae 

  • {{ post.author }}
  • Group: Members
  • Posts: 2862
  • Joined: 20-January 11
  • LocationWarwickshire, England
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 23 May 2012 - 01:37 PM (#12)

Matrices are funner
Front-end developer and writer
Twitter | GitHub | phpBB Contributor and Website Team Member | lynxphp
0


User is offline iCyan 

  • Group: Members
  • Posts: 204
  • Joined: 15-May 11
  • Expertise:HTML,CSS,Graphics,Flash

Posted 23 May 2012 - 02:38 PM (#13)

View Postianonavy, on 23 May 2012 - 12:53 PM, said:

Actually, Work is energy, so it's a scalar quantity.

Actually, actually, work is the change in energy :P
iCyan Allias
0


User is offline NeilHanlon 

  • Group: Members
  • Posts: 884
  • Joined: 08-July 10
  • LocationRowley, Massachusetts
  • Expertise:HTML,CSS,PHP,Java,Graphics

Posted 23 May 2012 - 05:50 PM (#14)

View Postianonavy, on 23 May 2012 - 12:53 PM, said:

Actually, Work is energy, so it's a scalar quantity. :P Also, as Rails said, adding vectors is easy. In Linear Algebra, vectors are represented by n x 1 matrices, where n is the number of dimensions. Adding two vectors is as simple as adding the components.


Work is Force over a distance, and the sum of two vectors is a scalar - sorry. Didn't mean to write Work as a vector.

Regardless, whether y'all think adding them is easy, I tend to think it's not. Maybe I just have a teacher who gives us harder problems to do. Who knows. It's my opinion on whether they're easy or hard to add, and you're entitled to your opinion as well. Just don't try to tell me my opinion is wrong...
Thanks,
兄ニール

Website | Blog | @NeilHanlon | About.Me | Facebook | LinkedIn
0


User is offline TheEmpty 

  • I say words in sequences.
  • Group: Members
  • Posts: 5154
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Python,Ruby on Rails,SQL

Posted 23 May 2012 - 06:46 PM (#15)

View PostNeilHanlon, on 23 May 2012 - 05:50 PM, said:

Work is Force over a distance, and the sum of two vectors is a scalar - sorry. Didn't mean to write Work as a vector.

Regardless, whether y'all think adding them is easy, I tend to think it's not. Maybe I just have a teacher who gives us harder problems to do. Who knows. It's my opinion on whether they're easy or hard to add, and you're entitled to your opinion as well. Just don't try to tell me my opinion is wrong...

It is wrong because you are too confused.
Reserved.
0


User is online Lemon 

  • I have a dream...
  • Group: Members
  • Posts: 688
  • Joined: 24-February 11
  • Expertise:HTML,CSS,PHP,Javascript,Node.js,SQL

Posted 23 May 2012 - 07:06 PM (#16)

View PostNeilHanlon, on 23 May 2012 - 05:50 PM, said:

Work is Force over a distance, and the sum of two vectors is a scalar - sorry. Didn't mean to write Work as a vector.

Regardless, whether y'all think adding them is easy, I tend to think it's not. Maybe I just have a teacher who gives us harder problems to do. Who knows. It's my opinion on whether they're easy or hard to add, and you're entitled to your opinion as well. Just don't try to tell me my opinion is wrong...

The sum of two vectors is definitely still a vector, even if the result is a zero-vector. Did you perhaps mean the scalar (dot) product, as that is analogous to the projection of one vector onto another (with extra cofactors for non-normalised vectors) and hence results in a scalar?

Quote

Force as a vector over a scalar distance would result in a vector.

If you're going to consider force as a vector you need also to consider displacement as existing within the same vector space, hence you use the scalar product from above to get derive a scalar work from the product of the two vectors.
Posted Image
In the end, it's not the years in your life that count. It's the life in your years
0


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users


Enter your sign in name and password


Sign in options
  Or sign in with these services