2.3 Friction Force - The Nature of Code

Поділитися
Вставка
  • Опубліковано 2 лют 2025

КОМЕНТАРІ • 135

  • @Edzward
    @Edzward 4 роки тому +121

    >knock knock
    >Who is it?
    The best teacher on UA-cam!

    • @ramesh.programming
      @ramesh.programming 4 роки тому +5

      😂😂❤️

    • @Brahvim
      @Brahvim 4 роки тому +1

      @Luka Igrutinovic Professor Daniel Shiffman! :D!

  • @VerdianaYT
    @VerdianaYT 4 роки тому +35

    Watching you code is amazing, I find it relaxing and always learn something!

  • @lexus4tw
    @lexus4tw 4 роки тому +2

    I'm an embedded system engineer, I heard some mechanic lectures during my studies and really enjoy your videos, opens some new perspectives for me. Keep up your good work.

  • @cicizhang4487
    @cicizhang4487 4 роки тому +3

    I got here from your 2015 video, and now you have an ending scene! amazing!! lol I'm actually touched that your're still making great tutorial videos. >w

  • @dave6012
    @dave6012 3 роки тому +1

    I wonder why it took me learning to code to begin to grok the concepts of geometry and physics…. Must be Daniel’s excellent teaching style!

  • @RyanDurbin10
    @RyanDurbin10 2 роки тому +1

    Thanks!

    • @RyanDurbin10
      @RyanDurbin10 2 роки тому

      Thank you for everything you do to teach us coding. You're examples are amazing and you break down problems into bite size units that we all appreciate.

    • @TheCodingTrain
      @TheCodingTrain  2 роки тому

      Thank you for the support!

  • @bhajanpreet25
    @bhajanpreet25 4 роки тому +15

    Two of my favourite subjects married together! Physics and Code 😅

  • @jorgeferreira6727
    @jorgeferreira6727 3 роки тому +2

    The quick and dirty mock up for friction has a major problem.
    It will generate a friction even when not in contact with any surface, and in all directions of space.
    BTW the more complete model also has a little flaw, friction will occur even with a perfect vertical motion when there is no rubbing against the surface (no horizontal component of velocity)

    • @kjanimates
      @kjanimates Рік тому

      I agree with that guy ☝️

  • @Deditzy.
    @Deditzy. 4 роки тому +12

    Hey Dan, the friction force would not affect the “y-component” (in this case) of the velocity. I fear it may misbehave later on when we have a more complex system based off this groundwork.

    • @RupertBruce
      @RupertBruce 3 роки тому +1

      It wouldn't affect y for a flat surface but if the surface is sloped, y would be affected - especially if the surface is vertical. Frictional should be proportional to the angle of incidence.

  • @JJZzZzZzZ
    @JJZzZzZzZ 3 роки тому

    Watching Daniel's videos b4 sleep rlly give me good dreams hahaha

  • @X22GJP
    @X22GJP 4 роки тому +2

    Excellent video, loving this series. I know the simulation you made there was basically a flat surface and shapes just moving with no motion other than in the x and y coordinate. What I’d be interested to know about is, when you have a sloped surface, is there a difference between a ball rolling down the surface, and a ball sliding down the surface? Instinctively I’d say yes I’d course there is, bur is the friction formula the same, just with more a more complex object? I guess another analogy would be hitting a pool ball with a cue. Depending on where you hit the ball, it might slide along the cloth for a bit and then start to roll.

  • @kajij
    @kajij 4 роки тому +11

    When you try to simluate ellastic collisions, how do you deal with intersecting/overlapping circles due to timesteps being too large? I found only very inaccurate solutions to this problem so far.

    • @bayramkazk5112
      @bayramkazk5112 4 роки тому +4

      +1

    • @rikilshah
      @rikilshah 4 роки тому +2

      Exactly. I was thinking the same.

    • @CalculusPhysics
      @CalculusPhysics 4 роки тому +3

      maybe you could try checking to see if the spheres *would* intersect in the next frame and then handle the collision a bit before they actually collide

    • @kajij
      @kajij 4 роки тому

      @@CalculusPhysics I did that, but the methods that I've seen so far do the following: get the overlap of the circles and move both circles away from each other by overlap/2. But this leads to problems. Imagine having two objects, one of them has a mass a million times larger than the other object. Both of them attract each other by gravitation. Pushing away the heavy object by overlap/2 would be very unphysical. I tried pushing only the light object away by the full overlap. But this often pushes away light objects into other light objects which then might cause chain reactions of acceleration due to gravitational forces being too strong. I haven't found a reasonable solution yet.

    • @Brahvim
      @Brahvim 3 роки тому +1

      Erin Catto explained Continuous Collision Detection in a GDC talk. Go there, perhaps?

  • @andrewmalaty8
    @andrewmalaty8 3 роки тому

    Super cool explanation! I think it's important to note that this only works for sliding friction and not rolling friction though.

  • @sweethomes674
    @sweethomes674 Рік тому

    Excellent explanations 😊Thank you

  • @shalomblau921
    @shalomblau921 3 роки тому +1

    There is a flaw in this code.
    When the ball is bouncing vertically relative to the ground (with no velocity on the x' axis) you adding the inverse of the velocity vector (wich pointing up) to the force.
    Another thing, the friction force vector can't point in a direction that is not parallel to the ground, so when the ball is bouncing, the friction force vector is totally off.

  • @gebinmaxeey
    @gebinmaxeey 4 роки тому

    Just bought a membership to support your channel!

    • @TheCodingTrain
      @TheCodingTrain  4 роки тому

      Welcome aboard! Thank you for the support! Choo choo!

  • @NicolasAmpuero
    @NicolasAmpuero 4 роки тому +5

    you are amazing, saludos desde Chile uwu

  • @deaddoctor
    @deaddoctor 4 роки тому +1

    You can also use forEach() instead of a loop:
    movers.forEach((mover) => {
    console.log(mover);
    });

  • @RicoGalassi
    @RicoGalassi 4 роки тому +1

    love this series!

  • @utna90
    @utna90 4 роки тому

    Hey Dan, what I could not get, is that even without friction, if we leave the ball just to do a free fall, it seems that it never returns to the same position and gradually loses velocity. But why is that? In the edge function we simply revert the object's velocity when it touches the surface, so it should go back to the same height. I mean, conservation of mechanical energy requires that, right?

  • @EVRIEONE1
    @EVRIEONE1 4 роки тому

    This is one talented man!

  • @grakatacc
    @grakatacc 4 роки тому +1

    may i ask what code displayer you use? l am looking for a good one.
    Very helpful and interesting video! Thank you!

    • @TheCodingTrain
      @TheCodingTrain  4 роки тому +2

      This is the p5.js web editor. editor.p5js.org/

    • @spotandjake1008
      @spotandjake1008 4 роки тому

      Another good online program is repl.it

  • @arnavsirigere2877
    @arnavsirigere2877 4 роки тому +1

    Great explanation 🌈🐱🚂

  • @yusufmirgoul3541
    @yusufmirgoul3541 4 роки тому

    never been this early to one of your videos. thanks buddy!

  • @Jorrit_200
    @Jorrit_200 3 роки тому

    Wouldn't the normal force be the total force in the direction of the floor (down) instead of the weight? So when you push the object against the floor the friction increases?

  • @stevencrews5796
    @stevencrews5796 Рік тому +1

    Here is an issue I encountered: When the bouncing object comes to within one pixel of the bottom, and we therefore calculate friction, it is likely to have a strong vertical component of velocity. So when we normalize our copy of the velocity vector it is not horizontal. So we end up with a friction force that is largely vertical in direction, which leads to some strange effects. It's not clear to me why this problem did not manifest in the video but it sure did in my code. I got around this by negating the vertical component of velocity after I copied it to create my friction, and before I normalized it. Like this:
    let friction = this.vel.copy(); // create friction vector as copy of velocity
    friction.y = 0; // zero out vertical component so that friction force will be horizontal
    friction.normalize(); // normalize F so it has same heading as velocity but magnitude of 1
    friction.mult(-1); // make it negative to reverse the heading
    Did anyone else deal with this issue?

    • @TheCodingTrain
      @TheCodingTrain  Рік тому +2

      Oh interesting! Do you see this issue in the code that is part of my new draft of Nature of Code: nature-of-code-2nd-edition.netlify.app/force/

  • @dobromirdobrev4692
    @dobromirdobrev4692 4 роки тому +1

    Keep up the good work. Do more fun and cool stuff, Dan !

  • @redeidolci2607
    @redeidolci2607 4 роки тому

    I have been following you for a few years and I started the "The nature of the code" section for a few weeks, I have one question: in calculating the normal force, should we multiply mass by the acceleration of gravity? (which we have set when we calculated the weight); because i suppose that normal force is less strong for example on the moon than on earth, in relation to the acceleration of gravity of each planet.

    • @pabloisapanda
      @pabloisapanda 4 роки тому

      If an object is at rest on a surface, then the Normal Force must be equal to the Gravitational force. Given that the object is not accelerating, the total force that object is experiencing is zero. You can calculate the Normal Force through the method you described, or you can simply set the magnitude of the force equal to the force of gravity.
      Please note that this only applies if: the surface that the object is resting on is perpendicular to the force of gravity. On a sloped surface, the normal force would be different because the normal force vector always points perpendicular to the surface that is applying the force.

  • @unknowunknow8637
    @unknowunknow8637 4 роки тому +3

    Can u make
    "The universe within" made by the art of code or make light/star trails or make bokeh/out of focus lights
    as a challange in processing pls ?

  • @manuelpellizzari8540
    @manuelpellizzari8540 4 роки тому +1

    Hi, I'm a fan of this channel and learned a lot thanks to you. But in this case, allow me to expreess that I find the application example of what you are showing quite strange. The friction force (as considered in the sledge drawing and the related formula) is the effect of the ground on the mover, and can only apply in a direction parallel to the ground. In the way you implement, the force has a component perpendicular to the ground as the mover bounces. And this "friction" is simply proportional to the mass of the object, although the reaction of the ground during the bounce is much higher (if we really wanted to apply the friction formula). So yes, it doesn't prevent the visuals from looking ok, but the implementation is disturbing.
    Also, the fact that the movers are circles sliding with a single point of contact and no rotation is an acceptable simplification, but gets in the way of feeling what the friction does. A flat surface of contact (with square movers) would be more adequate.

  • @manishscientist8322
    @manishscientist8322 4 роки тому

    Both are Best UA-cam 🌍🌍channels.
    Physics=physics wallah😘
    Coding=The Coding Train😘

  • @alexsandergutierrezgoncalves
    @alexsandergutierrezgoncalves 3 роки тому +1

    how could I apply force to a slanted surface?

  • @RealHypeFox
    @RealHypeFox 4 роки тому +1

    I’m currently in a software engineer bootcamp and right now we’re learning Ruby. Would the “Nature of Code” help in all languages?

    • @TheCodingTrain
      @TheCodingTrain  4 роки тому +3

      You could apply these same concepts in Ruby yes! However, my examples are based on having a graphics / drawing environment so you would likely want something equivalent in Ruby.

    • @ABaumstumpf
      @ABaumstumpf 4 роки тому +3

      His videos are very nice for beginners to learn the concepts of programming as a whole. While you will need to learn the syntax of the language you are using, the way to break down problems stays mostly the same.

    • @RealHypeFox
      @RealHypeFox 4 роки тому +1

      I’ve been watching the videos for years, and he’s definitely been a big help as well as entertaining. Thank you guys for the feedback 🖤

  • @bel-gk-a2304
    @bel-gk-a2304 4 роки тому +1

    Thanks from Russia! :)

  • @RodrigoOliveira-gg3ij
    @RodrigoOliveira-gg3ij 4 роки тому

    Hi Dan. Is threre a way to construct a variable Force (on its acceleteration in direction). I would like to create a graphic that varies according to a force that for instance varies too. It is like na Eletrocardiogram of our Heart. There is a force, that is captrured as a vector, and this vectors varies over time in one cicle, and at the final we have the pictrure of a eletrocardiogram.

  • @Linus_19
    @Linus_19 4 роки тому

    How can I change the friction force? Great teaching!! :)

  • @paolobiolghini5245
    @paolobiolghini5245 4 роки тому +1

    i'm new in this channel , what software is this perfect teacher using?

    • @RockRespawn
      @RockRespawn 4 роки тому +3

      It's p5.js a JavaScript library I think he is using the online p5.js web editor

    • @paolobiolghini5245
      @paolobiolghini5245 4 роки тому +1

      Rock Respawn thanks

  • @srumut
    @srumut 4 роки тому

    Which one IDE are you using?

  • @snipbits6214
    @snipbits6214 4 роки тому

    cool video keep up the amazing work

  • @rivershen8199
    @rivershen8199 4 роки тому +1

    The coefficient is different for when the object is sliding vs rolling though

    • @arnavsirigere2877
      @arnavsirigere2877 4 роки тому

      But since both are constants, he took 0.1 for rolling friction so if he needs to implement sliding friction he can just take a larger number than .1

    • @rivershen8199
      @rivershen8199 4 роки тому +1

      @@arnavsirigere2877 Yeah but would be nice to mention it. You can never teach people too much physics!

    • @arnavsirigere2877
      @arnavsirigere2877 4 роки тому

      @@rivershen8199 Yup

  • @Acdic
    @Acdic 4 роки тому

    You are in godmode

  • @ojuswi
    @ojuswi 4 роки тому +6

    but the friction would also, start rotating the movers?
    *programmers thinking noises*

    • @ojuswi
      @ojuswi 4 роки тому +1

      @@lexus4tw yeah, for point masses, we don't have to worry about rotational motion

    • @lexus4tw
      @lexus4tw 4 роки тому

      @@ojuswi im actually not sure if it's the case here, because he applies friction based on the geometric parameters and the interaction with the surface, it's kind of a very simple model

    • @ojuswi
      @ojuswi 4 роки тому +1

      @@lexus4tw I think this lecture is specifically made to explain the friction, its application, and its formula. He might upload some other videos to explain rotation. Because rotation itself has its own large set of concepts.

    • @lexus4tw
      @lexus4tw 4 роки тому +1

      @@ojuswi yeah, and in this model there's no variable for angular velocity, so my first assumption was kind of right, right now the circle ist sliding along the surface

    • @Brahvim
      @Brahvim 4 роки тому

      They are particles for now xD
      His newest videos show rotation Physics.

  • @ellpell6550
    @ellpell6550 Рік тому

    Nice thanks!

  • @rezaz7167
    @rezaz7167 4 роки тому

    I had a bad day till I watched this

  • @cheako91155
    @cheako91155 4 роки тому

    I forgotten to say on your last video. U are deleting distance(== lower hight) by clipping to the boarder line, that's likely why your bounce eventually *stops. The equation should not be y = 0; or x = width; try x = width - x; or y = 0 - y;... y = -y; don't forget about "this.r" in your implementation. This works similarly for all 4 directions.
    * I see that fixing this ruins the demonstration here.

  • @legostroitel9429
    @legostroitel9429 4 роки тому

    How i can change the cursor position by code???????? Help me pleass

  • @tomasvaz9238
    @tomasvaz9238 4 роки тому +1

    Is there anyway to install p5js on Windows or any other app to replace it?

    • @spotandjake1008
      @spotandjake1008 4 роки тому

      There is processing which is not Javascript but desktop version p5.js is based on buy p5.js is a library for Javascript it runs on web

    • @spotandjake1008
      @spotandjake1008 4 роки тому

      P5. Js is not an app it is a library for Javascript so it runs on the web processing is the thing it is based on but it is not js if you want to make a desktop app with it and that is your question look into electron

    • @johnjelatis2033
      @johnjelatis2033 4 роки тому

      Are you looking for the editor? If so, here it is: editor.p5js.org/

    • @x-seronis-x
      @x-seronis-x 4 роки тому

      @@johnjelatis2033 alternately openprocessing.org has a ton (thousands) of user submitted p5js projects

  • @RupertBruce
    @RupertBruce 3 роки тому

    That shortcut to friction would be useful for air resistance

  • @qwertyking9627
    @qwertyking9627 4 роки тому

    hi mate, i want to if you're beginner where to start from on your channel, or any other suggestions there too many resources and direction where side to go to

    • @TheCodingTrain
      @TheCodingTrain  4 роки тому +2

      This is the playlist I have for beginners: ua-cam.com/play/PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA.html

  • @krishnaawasthi5692
    @krishnaawasthi5692 4 роки тому

    Please do it
    It would be awesome

  • @SimonTiger
    @SimonTiger 4 роки тому +1

    2:40 was priceless
    Also, FIRST!

    • @OblakSan
      @OblakSan 4 роки тому +1

      How did u comment this 3 days ago?

    • @hasanali6798
      @hasanali6798 4 роки тому +1

      3 days ago? Which algorithm did you used

    • @BenjaminAster
      @BenjaminAster 4 роки тому +1

      Don't you guys know Simon Tiger? He's a boy (maybe 11 years or so) and loves The Coding Train. Once, Daniel and Simon met up an programmed together.
      He got the video earlier because he's a channel member.

    • @SimonTiger
      @SimonTiger 4 роки тому

      @@OblakSan I'm a Member. By supporting Dan directly, I can watch all the videos ~1 day earlier than when they go live.

    • @OblakSan
      @OblakSan 4 роки тому

      @@SimonTiger aighy bet

  • @abcrtzyn
    @abcrtzyn 4 роки тому +7

    I was taught that the friction force is always perpendicular to the Normal force.

    • @X22GJP
      @X22GJP 4 роки тому +2

      The normal force is perpendicular to the angle of the two surfaces. The friction force is calculated based on this, not perpendicular to it. Ultimately the friction force is opposite to the direction of velocity.

    • @abcrtzyn
      @abcrtzyn 4 роки тому

      I’m not sure what you mean by angle. In the situation where the ball bounces, is the friction opposite velocity (up and down) or perpendicular to the normal/parallel to the surface (left or right).

  • @callofduty4702
    @callofduty4702 4 роки тому

    New to programming
    What programming language is he using?

  • @SimpleProgrammer0
    @SimpleProgrammer0 4 роки тому

    sout (Best Teacher)

  • @KanalMcLP
    @KanalMcLP 4 роки тому +1

    I think, you should have used boxes, as rolling friction works even different

  • @josecamacho2303
    @josecamacho2303 4 роки тому

    What if instead of multiplyng the whole velocity vector for 0.95 you just do it with its x value, so it doesnt take some of the vertical velocity, just to make that simplified version of friction a little more acurate, great video tho :D

  • @jakubkurdziel2407
    @jakubkurdziel2407 4 роки тому

    Im waiting for more

  • @BenjaminAster
    @BenjaminAster 4 роки тому +6

    Cool video, but where is Daniel Shiffman?

    • @leo848
      @leo848 4 роки тому +1

      Benjamin Aster WTF?

    • @BenjaminAster
      @BenjaminAster 4 роки тому +1

      @@leo848 It was meant to be a joke (he has a different haircut so you don't recogize him)

  • @faisal7823
    @faisal7823 4 роки тому +2

    When you’re a physics teacher and a programmer at the same time:

  • @meralozkoc4381
    @meralozkoc4381 4 роки тому

    I don't know where to start, please help me

    • @penta5421
      @penta5421 4 роки тому +1

      Depends on what you're trying to do, but for most things theres simple tutorials on UA-cam and the Internet in general that will teach you the basics. But you first gotta think in what direction you want to go, since that can and most likely will affect your choice of a programming language etc. When you have a decent understanding of the basics, just try to build something thats fun and/or useful and just look stuff up or seek help whenever you get stuck. Working on little projects helps applying all your knowledge and you learn a lot along the way, while also having a nice product at the end.

    • @TheCodingTrain
      @TheCodingTrain  4 роки тому +2

      This is the start of this series: ua-cam.com/play/PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM.html If you are a beginner to coding try this series: ua-cam.com/play/PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA.html

    • @meralozkoc4381
      @meralozkoc4381 4 роки тому

      @@penta5421 thank you very much. what do you suggest me

    • @meralozkoc4381
      @meralozkoc4381 4 роки тому +1

      @@TheCodingTrain First of all, thank you very much. By the way, I am Turkish. There are not many Turkish videos that can help me on UA-cam. I discovered you for that and I am really lucky. Even if you are on the other side of the world, I am trying somehow and I am determined in this business, I will learn. I watch your videos with subtitles. :)

    • @meralozkoc4381
      @meralozkoc4381 4 роки тому

      I'm translating my answer from google translated sorry if something went wrong

  • @stackercoding2054
    @stackercoding2054 2 роки тому

    looking up physics formulas honestly feels like looking at the universe docs, it feels really weird to me that someone could find this formulas

  • @PauloArthurCamposPalhano
    @PauloArthurCamposPalhano 4 роки тому

    👏🏻👏🏻

  • @the_gobbo
    @the_gobbo 4 роки тому

    Does anyone with experience in the area can tell me if it's possible to do the kind of content coding train uploads with C++ and opengl?
    I can't find the answer ;-;

    • @NeZversSounds
      @NeZversSounds 4 роки тому +1

      Language doesn't matter. Just find a library that takes care of drawing, like in the Coding Train uses p5.js for javascript. I'd suggest using a game framework like Raylib.

    • @the_gobbo
      @the_gobbo 4 роки тому

      @@NeZversSounds you think opengl can do it?

    • @NeZversSounds
      @NeZversSounds 4 роки тому +1

      @@the_gobbo Question is - Can you use OpenGL? Just use Raylib and that's it. Raylib is already set with anything you need, even preconfigured Notepad++ so you can write and compile on it from the get-go.

    • @the_gobbo
      @the_gobbo 4 роки тому

      @@NeZversSounds Thank you so much🥰, I'll check that out

  • @subhadipghorui2216
    @subhadipghorui2216 4 роки тому

    Hello, I am trying to make simulation on infection spreading with coronavirus social distancing by taking random variable with xy cord then select multiple infected point and map the point which are in 3m radias .......can give me some suggestions.
    It will be good in stuck at home.

  • @SrinivasMangipudi
    @SrinivasMangipudi 4 роки тому

    On a side note need help: p5js performance on mobile device is very slow and laggy. works great on desktop browser.

  • @jakehix8132
    @jakehix8132 4 роки тому

    that voice over scared the shit out of me

  • @vashupandey2212
    @vashupandey2212 4 роки тому +1

    hit the like for coding hero

  • @booyeah4874
    @booyeah4874 4 роки тому

    make this examples of natural phisics in native javascript code, pls. :c NOT FRAMEWORKS, PLUGINS, LIBRARYS, please. and thanks. regards from uruguay.

  • @TheHumanistX
    @TheHumanistX Рік тому

    Freaked me out. Haircut lol

  • @krishnaawasthi5692
    @krishnaawasthi5692 4 роки тому

    Do the challenge of coding jarvis

  • @rezaz7167
    @rezaz7167 4 роки тому

    Shiffman Therapy

  • @dangerkid7663
    @dangerkid7663 4 роки тому +1

    Hi second

  • @PedroHenrique-jy2dg
    @PedroHenrique-jy2dg 4 роки тому

    Can you make the balls to collide each other?

  • @kevinlascano8511
    @kevinlascano8511 4 роки тому

    Por favor, pon para subtítulos en español

  • @aaavvv9525
    @aaavvv9525 4 роки тому

    lame

  • @jakubkurdziel2407
    @jakubkurdziel2407 4 роки тому

    Im waiting for more