3.5: Springs - The Nature of Code

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

КОМЕНТАРІ • 39

  • @ranjannayyar3863
    @ranjannayyar3863 9 років тому +8

    I think the really good part of series is that you recommend some amazing exercises at the end.! I just love doing them. I did the same when we were doing gravitational force. I made 10 circles with some having gravitational attraction and some having repulsion. At a hundred my computer crashed. haha. But anyways the results were amazing.! Thanks a lot for making this video series.!

    • @TheCodingTrain
      @TheCodingTrain  9 років тому +2

      +Ranjan Nayyar Thanks for letting me know! Would love to see if you put any documentation online sometime.

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

    How did you calculate the direction of the vector? Subtracting the bob from the origin should create a vector that always points up (or down). Shouldn't you be subtracting the current length from the rest length?
    Please answer soon.
    Thanks.

  • @sociamix
    @sociamix 8 років тому +3

    I have to thank you again for this course ! It worth PVector.sub(sun.location, earth.location).mag() times every other book or tutorial on the subject, plus it's funny :D

  • @VISHNU-rr8gc
    @VISHNU-rr8gc 6 років тому +10

    I like how you clean entire board instead of the space you need. Half cleaned board kind of makes
    me uncomfortable. 😁😁

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

    Mind Blowing thanks

  • @brettbreet
    @brettbreet 8 років тому +1

    Hey, you asked if anyone had a question, so here's one!
    Can you create a pendulum from a spring with the resting length and starting length the same, giving an initial theta, and adding a gravity force? Is this a better way than the previous method since you can easily add other forces without having to worry about independent angular acceleration?

    • @wikipediaboyful
      @wikipediaboyful 6 років тому

      Bob b;
      void setup() {
      size(640, 360);
      b = new Bob(20, 0, 0); //mass,displacement,angle
      }
      void draw() {
      background(255);
      PVector g=new PVector(0, b.m*b.g);
      PVector wind = new PVector(1, 0);
      if (mousePressed) {
      b.apply(wind);
      }
      b.spring();
      b.apply(g);
      b.update();
      b.display();
      }
      //copy the following in another tab
      class Bob {
      PVector position;
      PVector velocity;
      PVector acceleration;
      PVector origin;
      float m, g, k, dx, slen, restlength, restDx;
      float theta;
      Bob(float a, float b, float angle) {
      theta=angle;
      m=a;
      float displacement=b;
      g=0.2;
      slen=150;
      k=0.5;
      restDx=m*g/k;
      restlength=slen+restDx;
      acceleration = new PVector(0, 0);
      velocity = new PVector(0, 0);
      position = new PVector((slen+restlength+displacement)*sin(theta)+width/2, (restlength+displacement)*cos(theta));
      origin = new PVector (width/2, 0);
      }
      void apply(PVector force) {
      PVector f=force.div(m);
      acceleration.add(f);
      }
      void spring() {
      PVector spring=PVector.sub(origin, position);
      spring.normalize();
      dx=position.y-restlength+restDx;
      spring.mult(k*dx);
      apply(spring);
      }
      void update() {
      velocity.add(acceleration);
      position.add(velocity);
      acceleration.mult(0);
      //velocity.mult(0.99);
      }
      void display() {
      line(position.x, position.y, width/2, 0);
      ellipse(position.x, position.y, 2*m, 2*m);
      }
      }
      //enjoy it mate ;)

  • @Shockszzbyyous
    @Shockszzbyyous 7 років тому +22

    spring force spring forces boing boing boing.

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

    I am in 10th grade and you make me understand everything....
    God give him some subscribe....😂

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

    Awesome lesson as always thank you sir!

  • @sallerc
    @sallerc 8 років тому +2

    Look at that, already watched the first three chapters.
    Regarding OO design and refactoring - as a long time Visual Studio/Resharper developer, that manual variable rename made me cringe :) Tempted to port some example to C#/Winforms and play with it. Anyway, thanks again for this awesome course! Keep up the good work!

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

    How does damping works in this case? Like in the last example?

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

    best teacher! 🙌🙏

  • @OonHan
    @OonHan 6 років тому +1

    Do the pendulum example but with interactivity with other forces: also a tension force from the rope!

  • @artyquantum7283
    @artyquantum7283 5 років тому

    Thanks for the effort and such wonderful content.
    Now that we have been introduced to the constraints like more specifically Force constraint, do you have any plan to do Energy constraints ? May be in future ? They have always puzzled me that how can they calculate the position from the Energy equations.

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

    He knows the public reaction assessing his class and recalling it? or just simulating?

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

    What is the uses of all of this thing? I just want to know. I'm a novice so dont get me wrong.

  • @ruonanchang1996
    @ruonanchang1996 7 років тому

    I have a question here!!!! you used PVector.sub(bob.location,origin) to calculate the direction of the spring force, but later you multiply (-k * stretch), Doesn't negative k actually reverse the direction of the spring force???

    • @musqueti.8131
      @musqueti.8131 6 років тому +3

      The formula itself says F = -k * x, so.. it's just the way it is supposed to be. But the direction vector actually doesnt tell us much about the direction, since it's normalized and points into the same direction - down (it's always (0, 1)). It is the stretch variable (or the difference of lengths) that gives us info about the real direction of the force. (based on what's bigger - current length or rest length)... I don't think you really needed an explanation or cared about it anymore, but I guess I wanted to explain it at least to myself. :D

  • @zoilo87
    @zoilo87 7 років тому

    How do i decompile the map function()?

    • @zoilo87
      @zoilo87 7 років тому

      in processing

    • @Shockszzbyyous
      @Shockszzbyyous 7 років тому

      what do you meen. like decompile the java byte code back into something readable (ish) or something else?

    • @Kitulous
      @Kitulous 6 років тому

      if you need how know how it works, it simply renders a1, b1 to a2, b2.
      Given a1=0, b1 = 1 (our original bounds), a2=100, b2=300 (our desired bounds), we can think: if x (first argument of map(x,a1,b1,a2,b2) function) equals to 0, then a2 equals 100, because 0 is our lower bound and it corresponds to 100, our another lower bound. If x=0.5 (the middle between 0 and 1), then the result should also be in the middle between 100 and 300, giving us 200.
      So:
      float percentage = x / (a1+b1); // percentage is the float around [0; 1] that shows the position in the rendering. E.g. x=0.5 in our first example would give us the percentage of 0.5
      float result = a2 + percentage*(b2-a2); // this projects the percentage on the desired bounds basing on the given bounds.

  • @zicary1636
    @zicary1636 5 років тому

    Mine doesnt work

  • @wikipediaboyful
    @wikipediaboyful 6 років тому

    something is wrong here: github.com/shiffman/The-Nature-of-Code-Examples/blob/master/chp03_oscillation/NOC_3_11_spring/NOC_3_11_spring.pde#L56
    here in setup()
    // Note third argument in Spring constructor is "rest length"
    spring = new Spring(width/2,10,100);
    bob = new Bob(width/2,100);
    if the rest length is 100, and the bob "y" location is 100, then why as soon as I start the program the bob oscillates? It shouldn't.

    • @wikipediaboyful
      @wikipediaboyful 6 років тому

      I understood why, when both bob location and rest length are equal is when the system is at equilibrium, but there's no notion of this in the program, there isn't something like stretch*K=m*g. And even worst when we introduce a displacement from the rest position, that displacement should be produce by a new force, like a hand pulling the bob down.
      I'm having a real headache coding this, I've been coding half a day this situation hahaha

    • @wikipediaboyful
      @wikipediaboyful 6 років тому

      solve it, if someone here is watching, on spring class_: void connect(Bob b), "float stretch = d - len;" , it should be "float stretch = d - len+m*g/k;" which adds the displacement produced by the bob at the rest position with the bob attached to the spring. Because in Hook's law, the displacement deltaX is calculated from the spring length with no mass in it. If we say stretch=d-len, and we draw the bob at rest position, d-len=0, which only adds gravity to the bob, which caused an initial oscillation at the beginning where it shouldn't.

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

    Please, I have to know "the shaker" inside joke at least when the p5js noc springs video comes out!

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

      I think he was alluding to the idiom "movers and shakers", which refers to people that get things done.

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

      @@baphnie thanks! :)

  • @Ikpoppy
    @Ikpoppy 7 років тому +2

    Still watching 20:11

  • @tinynova
    @tinynova 8 років тому

    Broken Github link in description :/

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

    I have a project for you! Why not have a "drop a slinky" challenge. If you've never seen it in slow mo. Please check it out

  • @zicary1636
    @zicary1636 5 років тому

    You didnt explain what you did!

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

    i love u

  • @arsalankhosrojerdi1475
    @arsalankhosrojerdi1475 5 років тому

    cocaine is bad