Higher-Order Fun

Game Design & Game Programming

Math for game programmers 03 – Geometrical representation of vectors

In the previous post, we introduced vectors, and showed some very elementary uses for them. We presented them as a simple and convenient way to pack a number (3, in our case) of scalar values into a single object. Now, we’ll consider their geometrical representation, which will help you grasp them more intuitively. For simplification’s sake, we’ll use two-dimensional vectors for all our examples, but the same extends to 3D vectors.

Points

First, consider two points, A and B. A is located at (1, 2), and B is located at (4, 3) (If you are unfamiliar with the cartesian plane, points are represented as coordinate pairs in the form (x,y), so (1, 2) means that A is at x=1 and y=2), as shown in the following picture:

vectors_fig1As we’ve mentioned in the previous post, positions in space can be represented as vectors. So we would have a vector A and a vector B, each representing one of the points in the figure. But points are not the SAME as vectors! A vector should always be thought of as a “delta”, it’s merely an increment. Without a reference, it’s meaningless as a position. For points, we adopt the point (0,0) as our origin (represented by the letter O), so all points can be represented as a vector from the origin. Drawing our vectors as arrows, we get this:

vectors_fig2Consider it for a moment. If we have O=(0,0), and we add a vector A=(1,2) to it, you’ll get the point (0+1, 0+2) = (1,2), which is exactly our original point A. However, vector A by itself is merely an increment of 1 in x and an increment of 2 in y… As such, we could also represent it as:

vectors_fig4This might all sound confusing, but don’t worry, it’ll eventually “click” into place! If you don’t fully understand the concept now, don’t worry about it.

Addition and Subtraction

What if you took vector B and subtracted A from it? From our previous lesson, we know that B – A is simply (B.x – A.x, B.y – A.y), so, given that B = (4, 3) and A = (1, 2), B-A = (3, 1). Let’s call that vector “C”. If we do A + C, we should naturally get B back: (1, 2) + (3, 1) = (4, 3). If you remember that we said that vectors are merely offsets, then this means that we can represent C as the vector that takes “A” and turns it into “B”, as in the following picture:

vectors_fig3If you look to the axes, you’ll see that vector C (the orange vector) spans x from 1 to 4, meaning that its x component is 3 (4-1), and y from 2 to 3, meaning that its y component is 1 (3-2).

Length and Distances

The geometrical representation of vectors leads to a very intuitive way to understand one of their most important operations, length. The length of a vector (or magnitude) is simply its geometrical length! Take vector B, for example. It has a x component of 4, and a y component of 3. How can we get its length? The pythagorean theorem solves that for us: we simply take the square root of the sum of its squared components. For a 2D vector, length = sqrt(x²+y²). For a 3D vector, length = sqrt(x²+y²+z²), and so forth.

For example, the length of vector B is sqrt(3²+4²) = sqrt(25) = 5.

One immediate use for the length operation is to find distances. Say that you want to find the distance between points A and B. You subtract one from the other (order doesn’t matter), and take its length. In C++, that would look as simple as:


float distance = (a-b).length();

The reason why the order of the subtraction doesn’t matter is that (A-B) results in the opposite vector of (B-A), that is, a vector with the same length, but opposite direction. A-B results in (-3,-1), and B-A in (3,1). Both have a length of sqrt(10).

47 ResponsesLeave one →

  1. They have tinier fins with a heart shaped
    back fin. This allows a migration path from the today´s stage of
    development to the point of using the Gen – IVI-standard-system.
    The result is a stronger, leaner, body and increased cardiovascular
    fitness.

  2. Hi, I read your blog occasionally and I own a similar one and I was just wondering if you get a lot of
    spam responses? If so how do you reduce it, any plugin or anything you can suggest?
    I get so much lately it’s driving me insane so any help is very much appreciated.

  3. Hello there! I could have sworn I’ve been to this blog before but after reading through some of the post I realized it’s new to me.
    Anyhow, I’m definitely delighted I found it and I’ll be book-marking and checking back often!

  4. I am starting up a internet website directory and was wanting to know if I can submit your blog?

    I’m trying to grow my directory slowly by hand so that it retains quality. I will make sure and put your blog in the proper category and I’ll also use, “Math for game programmers 03″ as your anchor text.
    Be sure to let me know if this is okay with you by emailing me.
    Cheers

  5. Hi there, I discovered your blog via Google even as searching for a similar matter,
    your site came up, it appears great. I have bookmarked it in my google bookmarks.

    Hi there, simply was alert to your weblog via Google, and found that it is really informative.

    I am going to watch out for brussels. I will appreciate
    for those who proceed this in future. Numerous other people shall be benefited out of your writing.
    Cheers!

  6. Greetings from Colorado! I’m bored to tears at work so I decided to browse your blog on my iphone during lunch break. I love the information you present here and can’t
    wait to take a look when I get home. I’m surprised at how quick your blog loaded on my phone .. I’m not even using WIFI, just 3G .
    . Anyhow, amazing site!

  7. Fantastic website. A lot of helpful info here. I’m sending it to several buddies ans additionally sharing in delicious. And obviously, thanks to your sweat!

  8. Sweet blog! I found it while surfing around on Yahoo News.
    Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Cheers

  9. Hi! I know this is kinda off topic nevertheless I’d figured I’d ask.
    Would you be interested in trading links or maybe guest writing a blog post or vice-versa?

    My site covers a lot of the same topics as yours and I think we could greatly benefit from each other.
    If you’re interested feel free to shoot me an e-mail. I look forward to hearing from you! Great blog by the way!

  10. I have learn several good stuff here. Definitely price
    bookmarking for revisiting. I wonder how a lot attempt you place to create one of these fantastic informative web site.

  11. I constantly emailed this blog post page to all
    my friends, for the reason that if like to read it after that my contacts
    will too.

  12. When someone writes an paragraph he/she retains
    the image of a user in his/her mind that how a user can know it.

    Thus that’s why this piece of writing is outstdanding. Thanks!

  13. Hey there, I think your site might be having browser compatibility
    issues. When I look at your website in Opera, it looks fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that,
    superb blog!

  14. I have read so many posts concerning the blogger lovers however this article is truly a good paragraph, keep
    it up.

  15. It’s a shame you don’t have a donate button! I’d definitely donate to this excellent blog! I suppose for now i’ll settle
    for book-marking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will talk about this blog with my Facebook group.
    Chat soon!

  16. Hello there! This post could not be written much better! Looking at this article reminds me of my previous
    roommate! He always kept preaching about this.
    I am going to forward this article to him. Fairly certain he’s going to have a great read. Thanks for sharing!

  17. Excellent weblog right here! Additionally your web site lots up very fast!
    What host are you the usage of? Can I am getting your affiliate hyperlink in
    your host? I desire my site loaded up as quickly as yours lol

  18. Admiring the time and effort you put into your website
    and detailed information you present. It’s good to come across a blog every once in a while that isn’t the same out of
    date rehashed material. Great read! I’ve bookmarked your site and I’m adding your
    RSS feeds to my Google account.

  19. Because the admin of this web site is working, no doubt very soon it will
    be famous, due to its quality contents.

  20. I am not sure where you are getting your information, but good topic.
    I needs to spend some time learning much more or understanding more.
    Thanks for magnificent information I was looking for this info for my mission.

  21. I got this web page from my pal who told me
    about this website and now this time I am visiting this website
    and reading very informative content at this time.

  22. My family every time say that I am killing my time here at net,
    but I know I am getting know-how every day by reading such fastidious articles or
    reviews.

  23. Does your blog have a contact page? I’m having a tough time locating it but, I’d
    like to send you an email. I’ve got some suggestions for your blog you might be interested in hearing.
    Either way, great blog and I look forward to seeing it develop over time.

  24. Hi i am kavin, its my first occasion to commenting anywhere, when i read
    this article i thought i could also make comment due
    to this good piece of writing.

  25. Fantastic beat ! I wish to apprentice while you amend your
    website, how could i subscribe for a blog site? The account aided
    me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear concept

  26. It’s very effortless to find out any matter on net
    as compared to books, as I found this article at this
    web page.

  27. I don’t even know how I ended up here, but I
    thought this post was great. I don’t know who you are but certainly you are going to a famous blogger
    if you aren’t already 😉 Cheers!

  28. Woah! I’m really loving the template/theme of this site.
    It’s simple, yet effective. A lot of times it’s very difficult to get that “perfect balance” between usability
    and visual appearance. I must say you’ve done a excellent job with this.
    In addition, the blog loads extremely fast for me on Safari.

    Exceptional Blog!

  29. I have been exploring for a bit for any high-quality articles or blog posts on this sort of area
    . Exploring in Yahoo I eventually stumbled upon
    this web site. Studying this info So i am satisfied to exhibit that I’ve a very just right uncanny feeling I discovered exactly what
    I needed. I most unquestionably will make sure to do not fail to remember this website and provides it a glance regularly.

  30. Thank уou foг sharing your thoughts. I really appreciate your efforts and I am waiting for your next post thanks once again.

  31. You actually make it seem so easy with your presentation but I find this matter to be really
    something which I think I would never understand.
    It seems too complex and extremely broad for
    me. I am looking forward for your next post, I will try to get the hang of it!

  32. Thanks , I have recently been searching for information approximately
    this topic for a long time and yours is the best I’ve found out till now.
    But, what about the bottom line? Are you sure about the source?

  33. Hello there! This is my first visit to your blog!
    We are a team of volunteers and starting a new project in a community in the same niche.

    Your blog provided us beneficial information to work on.
    You have done a extraordinary job!

  34. You’re so interesting! I do not think I’ve truly read something like
    that before. So great to discover someone with original thoughts on this subject.
    Seriously.. many thanks for starting this up. This web site is something that is
    required on the internet, someone with some originality!

  35. I really like looking through an article that can make people think.
    Also, thanks for allowing for me to comment!

  36. Definitely believe that which you said. Your favorite reason seemed to be
    on the net the simplest thing to be aware of.
    I say to you, I certainly get irked while people think about
    worries that they just don’t know about. You managed to hit the nail upon the
    top and defined out the whole thing without having side-effects ,
    people can take a signal. Will probably be back to get more.
    Thanks

  37. I every time used to study article in news papers but now as I
    am a user of internet therefore from now I am using net for content,
    thanks to web.

  38. Hello there! I could have sworn I’ve been to this blog before but after browsing through a few of the posts I realized it’s new to me.
    Nonetheless, I’m definitely happy I stumbled upon it and I’ll be
    bookmarking it and checking back frequently!

  39. I like the valuable information you supply on your articles.
    I’ll bookmark your weblog and take a look at again right here regularly.
    I am relatively certain I will be informed lots of new stuff proper here!

    Best of luck for the following!

  40. I think this is among the most vital info for me. And i
    am glad studying your article. However should remark on few
    basic issues, The web site style is wonderful, the articles is in reality nice : D.
    Just right task, cheers

  41. nita2506

     /  2014-06-09

    Hey there. Have you figured out steps to make a site cell phone hospitable?
    I’m trying to find a topic or plugin that could possibly clear up this challenge. Please share if you have any suggestions.
    Brief question that’s thoroughly off of theme.
    My site appearances bizarre when surfing.

  42. buy twitter followers 20000

     /  2014-06-19

    Fantastic goods from you, man. I’ve remember your stuff previous to and you are just extremely magnificent. I actually like what you have acquired right here, certainly like what you’re saying and the way wherein you are saying it. You’re making it enjoyable and you still care for to stay it smart. I can not wait to learn far more from you. This is really a tremendous web site.

  43. Aw, this was an exceptionally nijce post. Finding the time and actual effort to make a
    great article… but what can I say… I hesitate a whole lot and don’t manage to get nearly anything done.

  44. There is a huge number of sites willing to help you sell accounts, and a small number of them will pay for certain accounts upfront.
    If you are unfamiliar with the affiliate marketing model, it’s quite a simple process within itself.

    com will also powerlevel your character to a level of your choice as well as
    their ‘build an account’ option which allows you to choose which level your character
    will be when you buy it.

  45. each time i used to read smaller articles which as well
    clear their motive, and that is also happening with this article
    which I am reading at this place.

  1. Math for Game Programmers 05 – Vector Cheat Sheet | Higher-Order Fun
  2. Matemática para programadores de Jogos: Vetores |

Leave a Reply to Asphalt 8 Airborne Hack Android

*