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.
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
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.
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)
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.
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.
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.
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.
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
@@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.
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.
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?
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?
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?
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.
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.
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 ?
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.
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.
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.
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.
@@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
@@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.
@@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
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.
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
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
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.
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.
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).
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
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.
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
@@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. :)
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 ;-;
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 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.
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.
>knock knock
>Who is it?
The best teacher on UA-cam!
😂😂❤️
@Luka Igrutinovic Professor Daniel Shiffman! :D!
Watching you code is amazing, I find it relaxing and always learn something!
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.
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
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!
Thanks!
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.
Thank you for the support!
Two of my favourite subjects married together! Physics and Code 😅
Fine, nd ur child is Math.
@@manishscientist8322 Not mine theirs.
@@bhajanpreet25 😂 LoL
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)
I agree with that guy ☝️
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.
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.
Watching Daniel's videos b4 sleep rlly give me good dreams hahaha
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.
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.
+1
Exactly. I was thinking the same.
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
@@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.
Erin Catto explained Continuous Collision Detection in a GDC talk. Go there, perhaps?
Super cool explanation! I think it's important to note that this only works for sliding friction and not rolling friction though.
Excellent explanations 😊Thank you
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.
Just bought a membership to support your channel!
Welcome aboard! Thank you for the support! Choo choo!
you are amazing, saludos desde Chile uwu
You can also use forEach() instead of a loop:
movers.forEach((mover) => {
console.log(mover);
});
love this series!
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?
This is one talented man!
may i ask what code displayer you use? l am looking for a good one.
Very helpful and interesting video! Thank you!
This is the p5.js web editor. editor.p5js.org/
Another good online program is repl.it
Great explanation 🌈🐱🚂
never been this early to one of your videos. thanks buddy!
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?
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?
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/
Keep up the good work. Do more fun and cool stuff, Dan !
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.
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.
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 ?
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.
Both are Best UA-cam 🌍🌍channels.
Physics=physics wallah😘
Coding=The Coding Train😘
how could I apply force to a slanted surface?
I’m currently in a software engineer bootcamp and right now we’re learning Ruby. Would the “Nature of Code” help in all languages?
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.
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.
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 🖤
Thanks from Russia! :)
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.
How can I change the friction force? Great teaching!! :)
i'm new in this channel , what software is this perfect teacher using?
It's p5.js a JavaScript library I think he is using the online p5.js web editor
Rock Respawn thanks
Which one IDE are you using?
cool video keep up the amazing work
The coefficient is different for when the object is sliding vs rolling though
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
@@arnavsirigere2877 Yeah but would be nice to mention it. You can never teach people too much physics!
@@rivershen8199 Yup
You are in godmode
but the friction would also, start rotating the movers?
*programmers thinking noises*
@@lexus4tw yeah, for point masses, we don't have to worry about rotational motion
@@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
@@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.
@@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
They are particles for now xD
His newest videos show rotation Physics.
Nice thanks!
I had a bad day till I watched this
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.
How i can change the cursor position by code???????? Help me pleass
Is there anyway to install p5js on Windows or any other app to replace it?
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
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
Are you looking for the editor? If so, here it is: editor.p5js.org/
@@johnjelatis2033 alternately openprocessing.org has a ton (thousands) of user submitted p5js projects
That shortcut to friction would be useful for air resistance
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
This is the playlist I have for beginners: ua-cam.com/play/PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA.html
Please do it
It would be awesome
2:40 was priceless
Also, FIRST!
How did u comment this 3 days ago?
3 days ago? Which algorithm did you used
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.
@@OblakSan I'm a Member. By supporting Dan directly, I can watch all the videos ~1 day earlier than when they go live.
@@SimonTiger aighy bet
I was taught that the friction force is always perpendicular to the Normal force.
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.
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).
New to programming
What programming language is he using?
David Ramos JavaScript
JavaScript P5
sout (Best Teacher)
I think, you should have used boxes, as rolling friction works even different
great point!
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
Im waiting for more
Cool video, but where is Daniel Shiffman?
Benjamin Aster WTF?
@@leo848 It was meant to be a joke (he has a different haircut so you don't recogize him)
When you’re a physics teacher and a programmer at the same time:
I don't know where to start, please help me
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.
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
@@penta5421 thank you very much. what do you suggest me
@@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. :)
I'm translating my answer from google translated sorry if something went wrong
looking up physics formulas honestly feels like looking at the universe docs, it feels really weird to me that someone could find this formulas
👏🏻👏🏻
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 ;-;
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.
@@NeZversSounds you think opengl can do it?
@@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.
@@NeZversSounds Thank you so much🥰, I'll check that out
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.
On a side note need help: p5js performance on mobile device is very slow and laggy. works great on desktop browser.
that voice over scared the shit out of me
hit the like for coding hero
make this examples of natural phisics in native javascript code, pls. :c NOT FRAMEWORKS, PLUGINS, LIBRARYS, please. and thanks. regards from uruguay.
Freaked me out. Haircut lol
Do the challenge of coding jarvis
Shiffman Therapy
Hi second
Can you make the balls to collide each other?
Por favor, pon para subtítulos en español
lame
Im waiting for more