1.1: Vectors – The Nature of Code

1.1: Vectors – The Nature of Code


okay here we are again this is exciting people life and what you’ve been looking forward to but I I for one have been looking forward to this get past some of these introductory videos we’re here I feel a little more comfortable you feel a little more comfortable we are getting ready to talk about this building block the building block of all of the examples that we’re going to look through it after this entire video series we’re going to look at physics simulation steering behaviors fractals genetic algorithms all sorts of stuff we need something to start with and the topic that is sort of the build the foundation for everything we’re going to build on is vectors so I want this video to really just answer one single what to two single questions a pair of questions if you will what is a vector and the second question really is why do we even care why if we are people who live our life’s live our lives walking around and sitting down and doing stuff and eating food and then sometimes getting at a computer and programming graphics why should we care about a vector so the first question what is a vector I’m supposed to answer that question okay so um yeah this is not the easiest question to answer first of all it has a lot of it’s kind of hard it’s complicated but you know let’s simplify it for ourselves let’s talk about a vector in two-dimensional space for a moment I know that we don’t live in two-dimensional space but we program a lot in two-dimensional space and we also have two-dimensional space this is kind of a two-dimensional space right here I’m doing weird things to the whiteboard hello anyway so I just forgot to start the timer but so how long I’ve been going with oh it’s been a minute but we’re gonna get to this question I feel awkward about it because I don’t want to give the wrong answer let’s just try let’s try you together um okay so what is the vector okay let’s draw a vector for a second we can represent a vector in two-dimensional space as an arrow it could actually represent into three-dimensional space as an arrow as well but let’s look at this this is our vector let’s think about this more a little more substance of detail a vector is something that has magnitude at a key concept here and two direction with an exclamation point to emphasize that point a vector has both magnitude and direction now looking at this arrow I think this stuff might be so long I think you want to figure this out already what is the magnitude what is the magnitude of this vector the magnitude of this vector we can say is the length of it or the size this is the magnitude of a vector is it a long arrow is it a short arrow what is the direction also perhaps a somewhat obvious question the direction of this vector is the direction that it’s pointing in right and arrow points in a particular direction we could formalize that right we sort of formalized magnitude by saying needle length like I could get out a ruler and measure it and that’s actually the magnitude of that vector we could say perhaps the direction is perhaps an angle relative to some axis like if we think of having an x axis a horizontal axis a line here the direction could be represented by an angle and I’m going to use the Greek letter theta somebody’s knocking the way it looks enough it eventually okay okay we cut seen back and we’re back sorry for the little interruption there so let’s think about vectors for a moment in a slightly different way let’s say you were giving directions to somebody from how to get from point A to point B you might say look you’re looking to leave this place that you’re in and run away and escape it’s not very far the door takes five steps forward let’s say four steps forward because it’s not that far one two three four turn 90 degrees to the right and take three steps goodbye one two three well I could draw that out of the board as one two three four steps turn to the right and one two three now if we look at this I started in point any and I ended up in point B and here is my vector this arrow describes how I get from point A to point B and this is on I keep looking at it gotta turn it off because I would like to look at you it this is just just us here this strange I don’t know place that we are okay um so this vector has four steps over here and three steps over here it turns out by the way what does this look like to you it looks like a right triangle with a right angle you might remember this thing called the Pythagorean theorem a squared plus B squared equals C squared the 3 4 5 triangle the length of this arrow is actually 5 we’re starting to see something here even though a vector conceptually is just this idea of an arrow it has a length and it has a way that it’s pointing the magnitude in the direction we also start to see here thing there seems to be some type of math related to this that has to do with things we learned in geometry and trigonometry and we can make an angle here we start saying sine of the angle is opposite over hypotenuse and cosine is well adjacent over hypotenuse hopefully I got that right what’s going on here well a vector can actually be separated into its components the X component and the y component we can see that over here here is the X component that length and this length here is the Y component so even though a vector K is expressed as an arrow length and magnitude it can also be expressed as a pair of numbers and x and a y now you might be that might sound familiar to you right when was the last time you wrote a processing sketch where you didn’t just stick at the very top of your program float X float Y and this is the moment where we have now answered our second question why do we care about vectors because we do this all the time we have x and y for position we’ve XP and wisely for velocity maybe we have X acceleration Y acceleration X wind Y wind X friction Y friction X blast y blast either you could come up with any variable its X Y this X Y this and then when you go into 3-2 your X Y & Z and X speed and Y is beans these mean you’re just this pile and pile variables but you can’t get control over and you’re doing the same stuff with them over and over again a simple thing you do with them over and over again is x equals x plus XP y equals y plus y speed right but then when y speed changes by gravity and then when X P changes by wind you just have all of this stuff happening over and over again and there might be there’s lots of mathematical functions that this is what I’ve just said this three times this is why we might this is why with we can rig very almost like prideful little the very first way of understanding why we care about vectors it’s just to say I don’t want to have this in my code I want to say instead of float X Y I want to say P vector position now P vector is a class in processing that makes an object which is a vector and we’re going to get into that I think I think this video it just needs to end and we’ll move on to the next one you can just watch them continuously but in the next video we’re going to get into the code more more deeply so let’s actually just go before we go to the next video walk I don’t walk over here to this blank space because this computer would sleep I know magic okay so look at this this is the bit of the pristine example of exactly what I’m talking about we have a processing sketch where this ball moving around the screen oh come on seriously computer well you can imagine little boo doo doo doo the ball bouncing around the screen this is so sad soul there we go okay um where where this processing sketch has an X to the Y for position and X being and y speed for essentially what we’re going to start calling velocity the velocity vector of this object of the shape that’s moving around the screen so what I would like to do for us your give you as an exercise before you move on to the next video is go and find a processing sketch sketch sketch it’s like a skit and a sketch can you make a prosthetic skip like program a skit that would be kind of interesting would it be entertaining to watch I don’t know find a sketch that you’ve made that were you model motion somewhere where you have X’s and Y’s and X B’s and Y’s needs go and find that sketch because in the next video we’re going to look at how we actually instead of just having x and y everywhere how we start using the p vector class describe the position of an object and the way that position changes over time so that’s what we’re going to do in the next sketch I’m going to dominat I’m going to walk through this particular example then you if you you’ll have found yours then you’ll try to add P vector into your sketch and then hopefully we will figure out some way that we can communicate to each other and you could ask me some questions and I could answer some questions because you are not a person you are just the strange lens staring at me in this creepy strange way I must stop this video now okay so I think this is good for now thank you for watching I really appreciate it if you’re still watching I’m kind of shocked and amazed actually but hopefully you’re learning something if you’re not you could just email me a complaint I would that would be fine I will accept all complaints okay I’m going to there’s a button after press over here to stop it okay goodbye

48 thoughts to “1.1: Vectors – The Nature of Code”

  1. Hello Daniel! I am an architect new to processing and I started by looking at the tutorials at the processing.org page (I've reached until the objects tutorial). Now I found this series of videos however, I saw that you take some things for granted like the bouncing ball code. Would you recommend going back to the processing.org page to finish these tutorials before wathcing your videos or should I carry on?

  2. Just found this video series and I'm interested in using this with high school students. I just wanted to know if PVector() was actually a wrapper class for another java class or did someone code all the functions. For example, javafx has the Point2D class with all the same functions.

    I'm asking because I don't want the student to rely on external libraries.

  3. Thank you! I just made a code pen based on this video. I'm looking forward to learning more from you. http://codepen.io/RichieKastl/pen/NdmeOq

  4. You have made processing so much fun. The way you interact and explain stuff is mad crazy. I can't imagine processing without you.

  5. I am only here for two reasons :
    1. My teacher couldn't explain to me clearly what the heck are vectors and more importantly why should we care about them.
    2. I love your videos it is so entertaining and fun to watch you explaining stuff in a simple way.

  6. Hi dan sorry this comment isnt really relevant to this video but your newer stuff is great. What books can you recommend for genetic algorithms and AI that are really worth my money or any other general books that are related to the type of code that you write. Thanks for all your help

  7. "I am applying for a new villain loan go by the name of Vector! It's a mathematical term of quantity represented by an arrow with both direction and magnitude because I am committing crimes with both direction and MAGNITUDE!"

  8. Hi Daniel, I have a question. How does Xpos being > than the Width or Xpos being < 0 cause the ball to bounce back I understand the code underneath does this however how does the Software detect the size of the canvas and bounce back? does the value drop to 0 on Xpos when the ball has traveled past 640 pixels?

  9. Hey! i watched your playlist about P5.js and learned a lot!
    I kept watching this playlist and stuff are making sense but i haven't tried programming in processing
    is there a playlist with the basics that i should watch before this?
    EDIT:
    Sorry, never mind, found it!
    for some reason, this video series was before the introduction to processing!
    Here it is, if anyone is wondering:
    https://www.youtube.com/watch?v=2VLaIr5Ckbs&list=PLRqwX-V7Uu6ZYJC7L-r6rX6utt6wwJCyi

Leave a Reply

Your email address will not be published. Required fields are marked *