Deriving 3D Rigid Body Physics and implementing it in C/C++ (with intuitions)

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 พ.ค. 2024
  • I explain all the derivations necessary to understand the basics of 3D rigid body physics intuitively and show how I implemented them from scratch in C/C++.
    Links to the listed references
    Physically Based Modeling
    graphics.pixar.com/pbm2001/
    or for a combined pdf
    graphics.stanford.edu/courses...
    My derviation for the derivative of the rotation matrix is based on theirs.
    Physics, Part 1: The Next Frontier
    chrishecker.com/Rigid_Body_Dy...
    I had the idea to derive the linear motion of the rigid body from the linear momentum as a result of reading his first article.
    Outro music
    • Zelda & Chill 3
    Thank you @MikelTBE for letting others use your amazing songs.
    I love listening to your Zelda & Chill albums while working on my projects.
    0:00 Intro
    1:20 Rigid body model
    2:30 Mass computation
    5:24 Linear motion
    9:29 Linear motion implementation 1
    10:56 Explicit Euler integration
    14:35 Linear motion implementation 2
    16:42 Rigid body orientation
    18:39 Angular velocity
    23:34 Angular velocity implementation
    23:59 Angular momentum
    30:11 Inertia intuition
    36:12 Angular motion implementation
    38:49 Results and comparisons
    41:15 The end
    #physics #simulation #gamedev

ความคิดเห็น • 117

  • @blackedoutk
    @blackedoutk  8 หลายเดือนก่อน +10

    As some of you have pointed out, I made a few minor mistakes while talking about the math. I want to summarize them in this comment.
    First, at 26:06 I inserted the rewritten vector triple product into the integral without putting parenthesis around the expression. So in every following expression, it looks like rho(r) is only multiplied with the right addend, when it actually must be multiplied with both of them.
    However, if you imagine that there are brackets around the sum expression or think about rho(r)dV as being the differential mass element of r, which is what I did and how this mistake even occurred, then everything is still correct.
    Secondly, at 26:15 I moved some parenthesis and said that this was possible because matrix multiplication is commutative. I meant to say associative of course. Matrix multiplication is not commutative in general.
    Thanks to @bartoszstyperek6306 and @jaborl mentioning these and sorry for any possible confusion.
    If you find further errors, I would appreciate them being pointed out as a reply to this comment, so they are easier to find.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      @@matthiasmax2849 Hey, I feel what you're saying. Unfortunately, I'm not really sure what to recommend. I didn't read one specific thing that taught me all of this, rather I picked up some things here and there.
      Are you studying computer science? That would definitely be a good starting point. I feel like what helped me was working through exercises and writing down derivations step by step, even if it felt kind of pointless.
      And I would still recommend to attend the available simulation lectures, regardless of whether you have all the necessary prior knowledge. If that is possible. I picked up most of the math I present in these videos because of the animation and simulation lectures. I felt damn hopeless in the beginning, but because I was so interested in this topic I learned much by googling the little things or watching a few niche TH-cam videos. Also, don't be afraid to ask your professors stuff.
      By the way, I also have a discord server now if you're interested, the link is in the comments of my second livestream. We could discuss this further over there.
      Man, do I sound that german 🙈I hope my english is still okay to listen to haha

  • @jackfrederiksen7979
    @jackfrederiksen7979 16 วันที่ผ่านมา +3

    I want to understand this video, yet my calculus knowledge is limited to a highschool-level course. Please remind me in 2-3 years to come back and rewatch this video so I can actually understand all the math

    • @blackedoutk
      @blackedoutk  8 วันที่ผ่านมา +1

      I created an entry in my calendar in 2 years:D see you on the other side 😤

  • @terrastudiosdev
    @terrastudiosdev 8 หลายเดือนก่อน +21

    FINALLLY!!! a new physics engine video 😀

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +2

      yayyyyy

  • @Kraypus
    @Kraypus 8 หลายเดือนก่อน +15

    It's always interesting seeing these types of videos, which are always rare to come across without obnoxious over-the-top narrating, I'm glad I subscribed :)

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +4

      That's nice to hear :)

  • @jellewestra
    @jellewestra 8 หลายเดือนก่อน +9

    Mate, your videos are amazing; a great balance between math and implementation! Thank you and keep posting :)

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +2

      Thank you, that's great to hear :) I feared there was too much math in this video

  • @cmedia425
    @cmedia425 หลายเดือนก่อน

    watched all the way through, very thorough video. amazing job

    • @blackedoutk
      @blackedoutk  หลายเดือนก่อน

      nice, thank you

  • @lucassamuel6069
    @lucassamuel6069 8 หลายเดือนก่อน +1

    Amazing video! I was looking for something like this for a long time

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +1

      Same :D Thanks!

  • @pugglez4798
    @pugglez4798 7 หลายเดือนก่อน

    This is great stuff, I subscribed. Looking forward to future videos incorporating forces and accelerations

    • @blackedoutk
      @blackedoutk  7 หลายเดือนก่อน

      Nice, thank you

  • @BonnieMallet
    @BonnieMallet 4 หลายเดือนก่อน

    Love it! Thanks! Keep them coming!

    • @blackedoutk
      @blackedoutk  4 หลายเดือนก่อน

      Great to hear, thank you

  • @nagisa1578
    @nagisa1578 หลายเดือนก่อน

    Thanks man, finally a video that not just scratches the topic of rigid bodies. After reading through a paper, watching this video makes me understand what I have read better. Thanks!

    • @blackedoutk
      @blackedoutk  หลายเดือนก่อน

      Glad it helped :) which paper did you read?

  • @williamchurch8401
    @williamchurch8401 8 หลายเดือนก่อน +1

    This is over my head but I’m trying to learn it. Your videos are gold for helping me make that leap. Thank you! I am very much looking forward to the next one. Please don’t stop! Your efforts are greatly appreciated!

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +1

      Thanks, glad to hear that :) I would recommend working through some exercises to get more comfortable with these concepts. Or even just writing down the derivations and trying to understand each step.

    • @williamchurch8401
      @williamchurch8401 8 หลายเดือนก่อน

      @@blackedoutk Will do! I"m brushing up on my calculus as well.

    • @tempname8263
      @tempname8263 2 หลายเดือนก่อน

      Try to check my comment up above, maybe it'll help?.. Maybe not

  • @MrHeinzelnisse
    @MrHeinzelnisse 7 หลายเดือนก่อน

    Nice! I'm trying to wrap my head around the XPBD paper and I newly discovered your videos, amazing work so far, can't wait for the upcoming videos! Next thing for me will be to get constraints working with rigid bodies, I'll most likely mess it up and then wait for you to explain it :D

    • @blackedoutk
      @blackedoutk  7 หลายเดือนก่อน +1

      Thank you! Happy to hear that :D Unfortunately it'll still take quite some time until I get there. If I could, I would pump out these videos weekly, but that's just not doable for me

    • @MrHeinzelnisse
      @MrHeinzelnisse 7 หลายเดือนก่อน

      @@blackedoutk That's totally understandable, with these kind of topics I value quality over quantity, watching a bad tutorial that makes you more confused than before is not a good experience. That's definitely not the case with your tutorials, so keep up the good work!

  • @stick-Iink
    @stick-Iink 8 หลายเดือนก่อน +1

    Really nice video!

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      Thank you!

  • @gedaliakoehler6992
    @gedaliakoehler6992 12 วันที่ผ่านมา

    Very good video. Nice job.

  • @ladyaliciaherrera3437
    @ladyaliciaherrera3437 7 หลายเดือนก่อน

    Excellent video!

    • @blackedoutk
      @blackedoutk  7 หลายเดือนก่อน +1

      Thank you! :)

  • @A_Random_Ghost
    @A_Random_Ghost 8 หลายเดือนก่อน +2

    Nice, very nice.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +1

      Thanks :)

  • @101arrowz
    @101arrowz 3 หลายเดือนก่อน

    My high school physics classes only taught rotational motion using moment of inertia as a scalar quantity - in hindsight, I think we only considered situations where an object was rotating about one of its principal axes. Learning about the matrix representation was a little mind bending :)
    Thank you for creating this excellent resource! I always thought physics engines in games used a bunch of hacky estimations to maximize performance, but your implementation is both mathematically grounded and seems relatively easy to optimize. Now I feel the urge to write one too...

    • @blackedoutk
      @blackedoutk  3 หลายเดือนก่อน

      Thank you for your kind comment :) I remember seeing the formulas for rotations about one principal axis in the formula book, but we never talked about it in high school unfortunately. Though we learned a bunch of other interesting stuff.
      I guess when the physics gets more advanced the solutions in games will become a lot more hacky, but yeah it is really cool these are basically one to one implementations. If you want to you should give it a try, especially in the end with collisions it’s gotta be a lot of fun to see the results. But I still have to do a bit of work until that‘s done

    • @tempname8263
      @tempname8263 2 หลายเดือนก่อน

      Yeah, you don't need an entire matrix though. One (diagonal) vector is enough. Inertia tensor is just meant to resize momentum into a velocity, and that's all it does. Insanely simple idea.

  • @jaborl
    @jaborl 8 หลายเดือนก่อน +8

    At 26:15, you said matrix multiplication is commutative but it is actually associative.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +2

      Thanks for pointing that out. I meant to say associative. Matrix multiplication is not commutative in general.

  • @AnimatorsPal
    @AnimatorsPal 11 วันที่ผ่านมา

    5:39 LOL 🤣🤣 Evil libraries

    • @blackedoutk
      @blackedoutk  8 วันที่ผ่านมา

      😬😬 boost is trauma inducing right 🥲

    • @AnimatorsPal
      @AnimatorsPal 8 วันที่ผ่านมา

      @@blackedoutk true!

  • @azmah1999
    @azmah1999 7 หลายเดือนก่อน

    Funny how at 6:15, you say you think of momentum as the "amount of movement power", since in French momentum translates to "quantité de mouvement", which literally translates to "amount of movement". So you actually were right all along haha. Great video !

    • @blackedoutk
      @blackedoutk  7 หลายเดือนก่อน

      Haha, thank you. That's so cool. In german it's very confusing unfortunately because momentum translates to "Impuls" but english impulse has another meaning and also the word "Drehmoment" which has "Moment" in it means torque

  • @pushqrdx
    @pushqrdx 8 หลายเดือนก่อน

    Great video, I have a question though, didn't you mention in one of the soft body videos that you can use a constraint to essentially have the effect of rigid body?

    • @blackedoutk
      @blackedoutk  7 หลายเดือนก่อน

      Thanks :) I don't think this would work using a single constraint, but with multiple it might be somewhat possible, like for the "rigid" cube in episode 1. Are you referring to that?
      There are a few problems when using multiple constraints to make an object rigid like in previous episodes.
      First, the mass properties aren't exactly correct, because you are dealing with point masses instead of a contiuous body. If you didn't tetrahedralize your mesh, the mass would even only lie on the surface of the model.
      Secondly, it is probably inaccurate and or very expensive, depending on the complexity of the model and how many iterations you perform. In comparison, simulating the dynamics of a rigid body like in this episode is almost free and independent of the model's complexity (assuming the initial inertia tensor is given). As an example, in the previous episode, if the solver was perfect, the tire wouldn't have been soft at all, because I set its inverse stiffness to zero. But since I only performed a limited number of iterations, which were already pretty expensive, the tire appeared to be soft.

    • @pushqrdx
      @pushqrdx 7 หลายเดือนก่อน

      @@blackedoutk I see, and yes, I was referring to the cube, great explanation. Thank you very much and keep up the videos I really enjoyed them.

  • @rizohashimi
    @rizohashimi 8 หลายเดือนก่อน +3

    Here is code for calculating mass of any triangular mesh with uniform density.
    def get_volume(indices:list, vertices:list) -> float:
    volume = 0.0
    for i,j,k in indices:
    a = vertices[i]
    b = vertices[j]
    c = vertices[k]
    e0y = b[1] - a[1]
    e0z = b[2] - a[2]
    e1y = c[1] - a[1]
    e1z = c[2] - a[2]
    volume += (e0y * e1z - e0z * e1y) * (a[0] + b[0] + c[0])
    volume /= 6.0
    return volume
    def get_mass(indices:list, vertices:list, density:float) -> float:
    return density * get_volume(indices, vertices)
    If you need Inertia tensor as well, it could be calculated at the same time with some changes.
    Note: triangle winding must be CCW.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      How did you come up with this? I tried to make sense of it but couldn't.

    • @rizohashimi
      @rizohashimi 8 หลายเดือนก่อน

      @@blackedoutk it's basically a volume integral reduced to a surface integral using divergence theorem.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      @@rizohashimi Ah nice! That reminds me of the paper "Fast and Accurate Computation of Polyhedral Mass Properties" by Brian Mirtich where he uses the divergence theorem to compute the inertia tensor. It was actually the first method I tried to use, but found it to be a bit too complicated 😅
      Although the volume computation you posted looks quite cheap. I wonder how it performs in contrast to the scalar triple product version

    • @rizohashimi
      @rizohashimi 8 หลายเดือนก่อน

      @@blackedoutk By the scalar triple product version you mean the one where you calculate volume of each tetrahedron?
      What's cool about this version is with some changes it could calculate the intertia tensor at the same time.
      IIRC it's from a paper "Polyhedral Mass Properties (Revisited)" by David Eberly.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +1

      @@rizohashimi Yeah the volume for each tetrahedron one. Yours has 2 subtractions more but only 3 multiplies instead of 9. But it's probably more about how simd compatible they are.
      You can actually combine the inertia combinutation with the volume for each tetrahedron version as well. In fact, that's what I did. Hopefully I can talk about that in the next episode.

  • @thebumblecrag61
    @thebumblecrag61 8 หลายเดือนก่อน

    Yes!

  • @niklaswagner6191
    @niklaswagner6191 8 หลายเดือนก่อน +1

    Very nice video on such an interesting topic.
    You've actually explained the spin instead of the angular momentum since you were using r and not x. In your notation it would be the angular momentum L = x x p and the spin N = r x p (with integrals).
    The problem you've faced with the referential density also holds for the integration limits. They would be also dependant on the actual rotation when you are using the inertial basis as coordinate representation.
    I made the observation, that many people get problems with rotations and transfomration matrices. The vectors r, r-~ and r-v all refere to the same vector in space, namely the vector from CM to the particle, but only represented in other coordinate systems. There isn't something rotated, it's just an projection to other basis vectors. You could try to store the Omega and N in body fixed coordinates, how it is often done in mechanical simulations. I guess that could save some matrix multiplications.
    Thanks for the video, I like to see you making progress. I liked the explanation to get the angular velocity with the rescaling, made it more intuitive what's inside the inertia tensor.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +1

      Thank you :) Definitely interesting, I didn't know there was a differentiation between the spin angular momentum and the orbital angular momentum. But I don't think it's necessarily wrong to still call it angular momentum, just a matter of which origin point is used.
      How would the density be dependent on the rotation in an inertia basis? I am not sure I understand. Also, while r, r-~and r-v refer to the same vectors in local coordinates, I am not sure this is the case for global coordinates. Maybe you have another intuition than I have?
      I thought about storing the angular momentum in local coordinates, this might be a good idea. Though I am not exactly sure because then you might have to rotate the torque vector. What would be the benefit of storing omega in local coordinates?
      I really appreciate your remarks, thanks

    • @niklaswagner6191
      @niklaswagner6191 8 หลายเดือนก่อน

      ​@@blackedoutk Thanks for your reply. I wasn't conscious of these english expressions for spin angular momentum and orbital momentum. For kinematics, you have to use the same reference point for induced torques, which is anyway convinient to take the center of mass for that.
      Something that really improved my unterstanding of physics and especially mechanics, was to think of vectors as arrows in the space instead of putting three number on top of each other. Mechanics works as well with these arrows, but we need number to describe these arrows. For that we can use a inertial fixed basis or any other, like body fixed. Then, r, r-tilde and r-v describe the same arrow in space, but with other numbers.
      After rewatching your the sequence I think I got it better. Your density function (rho) takes the vector in global coordinates and rho-tilde takes it in body fixed coordinates, which would be the only possibility to give a proper definition of the function.
      Lastly, I have never thought about integrating the angular momentum instead of the angular velocity. This could simplify many things and removes some exhausting derivatives and materix multiplications. I think expressing the torque vector in local coordinates could be already cheaper. Force elements are mostly mounted body fixed, so for rotaional springs/dampers, their force contributions are already in local coordinates. For induced torques by a globally given force, you either have to take force into local coordaintes or calculate r in global coordinates.
      Would be interesting to see some benchmark experiments with both approaches and whether you face any other problems like in time integration.
      Anyways, I am curious see the progress you're making :)

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +1

      ​@@niklaswagner6191 Such benchmarks would definitely be interesting. Though later I will probably stick to storing and integrating the angular velocity anyway, because that's how the XPBD paper does it.
      Your understanding of the density functions is how I imagined it, so the definition would then be rho(R, r) = rho-tilde(R^T*r).
      I try to think of vectors as arrows in space too. And even matrices as multiple arrows if applicable. I believe understanding these concepts is much easier with a visual intuition and find it quite unsatisfying when people introduce some theory (for example the inertia tensor) without providing an intuition for it. In my opinion, there should be some amount of focus on teaching that as well

  • @sargates
    @sargates 8 หลายเดือนก่อน

    I was really hoping you would use quaternions in this video, there aren't enough good videos about quaternions. Great video none the less

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      Oh. Sorry :/ What specifically would you want a video about quaternions to cover? I think the hardest part about them is getting a good visual intuition, which I currently don't have myself. I am glad you like the video despite missing quaternions

    • @Tannz0rz
      @Tannz0rz 8 หลายเดือนก่อน +1

      @@blackedoutk All of these computations can be performed using geometric algebra, which generalizes quaternions/rotors. I would encourage you to look up “May The Forque Be With You” by Leo Dorst & Steven De Keninck.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      ​@@Tannz0rz Ah, I've glossed over their website before, but it looks so complicated. What would be the benefit of understanding it?

    • @sargates
      @sargates 8 หลายเดือนก่อน

      ​@@blackedoutk For visualization there's the 3B1B video (which I'm sure you've already seen and if not give it a watch), but it *is* something that's 4D so there's never gonna be a perfect way to understand them visually (maybe I just tell myself that because I don't). What I'd like to see is a somewhat in-depth explanation on the implementation of how you might set them up and any of the math required to do that. I'm sure that if you ever touch on them in a future video it'll be great.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      @@sargates :D I have seen the 3B1B video at least partially, but it was quite some time ago, so I don't remember much. Might have to watch it again. Though implementing quaternions is doable without too many headaches I think, unlike understanding their 4D intuition.
      But maybe the geometric algebra guy in this thread has a point too. I just watched this video here th-cam.com/video/Idlv83CxP-8/w-d-xo.html and it sounds quite promising. Perhaps there is a better way to understand quaternions. It's just that there are a lot of other new concepts in geometric algebra as well.

  • @eliaspierre6303
    @eliaspierre6303 2 หลายเดือนก่อน

    I'm having some trouble implementing this into a blender simulation with simulation nodes. I've been trying for about a month, I keep coming back to this video as it is describes a simulation with assumptions very similar to mine such as using only point masses, constant density, etc. I was wondering if I could send an annotated photo of my simulation setup to you through email. I know you're using c++ but the node I'm using in blender are quite simple so I'm sure you'd be able to understand them. If not no worries though. Either way thanks for this video it explains it very concisely!

    • @blackedoutk
      @blackedoutk  2 หลายเดือนก่อน +1

      Unfortunately I don't have much time at the moment, but you can still send it to the email that is listed in the channel details/info. In a month or so I might be able to take a look at it. Apart from that you can also join my discord server and post it on there if it's not something that you wish to be kept private. Maybe somebody over there has an idea why it's not working

  • @echovictordcsworld
    @echovictordcsworld 8 หลายเดือนก่อน

    To ensure the determinant of the rotation matrix remains at 1.00000 can you not simply normalize the x y and z components before applying it to the mesh? Loving the videos, i am trying to create my own N-body gravity simulation in C++/OpenGL, and have been trying to wrap my head around rotation natrices and this video helped perfectly.

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      That's great to hear :) I haven't tried anything to fix the rotation matrix so far, but I think that while just normalizing the axes might help, it doesn't guarantee orthogonality. So you also need to ensure that all axes are perpendicular to each other. For that you could use cross products (normalized) or something like Gram-Schmidt. But I don't know which approach works best.

    • @richardbloemenkamp8532
      @richardbloemenkamp8532 4 หลายเดือนก่อน

      @@blackedoutk The book Game Programming Gems 1 for which you find a pdf online has a chapter 2.2 on "Integrating the Equations of Rigid Body motion" by Miguel Gomez on this subject. This chapter proposes a different integration variable "q" and also some references because it claims that the rotation-matrix method introduces error and requires regular reorthogonalization.
      BTW a lot of this rigid body math is also present in university level courses on mechanics, robotics and aerospace engineering.

    • @blackedoutk
      @blackedoutk  4 หลายเดือนก่อน +1

      @@richardbloemenkamp8532 Nice, thanks for sharing the resource. They use a unit quaternion q instead of a rotation matrix to avoid having to do a reorthogonalization. The quaternion just needs to be normalized after the update, which is easier. In the future I want to use quaternions too, but here I wanted to start with the basics.
      I noticed that too, that rigid body math is part of quite a few university lectures. Currently I am attending a robotics lecture and a lot of the stuff I researched for this video helped me to understand some of the topics faster. They also presented algorithms that build on top of these basics, like for chains of rigid bodies with joints (robots).

    • @tempname8263
      @tempname8263 2 หลายเดือนก่อน

      Best way is not to use rotation matrices. Just use rotors. Uhhh, most people aren't educated about them, though, right? Yeah, they call them quaternions/complex numbers :d

  • @Shikinoe93
    @Shikinoe93 8 หลายเดือนก่อน +1

    What a coincidence! I've also been working on implementing some rigidbody physics.
    I am currently trying to implement angular motion with a constant angular velocity, just for simplicity.
    I have a question: I have tried updating the rotation matrix as you did in the video: Cuboid->R += DeltaTime*Cross(Omega)*R (with a constant omega vector)
    However, when I do that, my rotation matrix is no longer a rotation matrix after a few thousand simulation steps (The determinant explodes into values like 200). I'm using a DeltaTime of 0.01, but I have the same problem with a DeltaTime of 0.001.
    Am I missing something? Do you normalize at some point?
    Thanks for the video btw

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +1

      Cool! The problem you are facing is completely normal, I talk very briefly about this at the end of the video. But to add to that, you can even make intuitive sense of it.
      What you are trying to do by adding Cross(Omega)*R to R itself is move the axes of R along their respective circular paths. As explained in the video, Cross(Omega)*R contains the velocities of each axis vector of R, which are tangent to the circles. Regardless of how small your step is, if you move some epsilon > 0 along the tangent line of a circle, you will always leave the circle. Resulting in a larger radius than previously. The axes increase in length.
      You can fix this by reorthogonalizing R after each simulation step if you wanted to continue to work with a rotation matrix. Another, probably better fix would be to use quaternions instead. I didn't do any of that in the video, for some of the footage I just used an even smaller time step 😅

    • @Shikinoe93
      @Shikinoe93 8 หลายเดือนก่อน +1

      @@blackedoutk Thanks for the answer. Yeah, I figured out that it was normal but I didn't think the drift would happen so fast especially because it seemed to work well in your video 😅. I implemented a solution using quaternion too but can't seem to figure out what to do with the derivative of the quaternion after computing it. Simply adding the derivative x DeltaTime doesn't seem to give any good results...

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      @@Shikinoe93 Probably because the captures weren't very long. I think I used 1ms for most of it and only 0.01 ms for the "phone" and the screw thing.
      Adding the derivative x DeltaTime should work. Though similar to how only orthogonal matrices (with a determinant of 1) describe rotations, only quaternions of unit length describe rotations. So you might want to normalize your quaternion after adding its delta value.

    • @Shikinoe93
      @Shikinoe93 8 หลายเดือนก่อน

      @@blackedoutk I'm getting much more stable results now with quaternions. The previous implementation with rotation matrices would explode depending on the DeltaTime. Still not getting to the precision I need though, I don't know what more I could do to improve the accuracy of the simulation. Even increasing the deltatime doesn't seem to change much...

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      @@Shikinoe93 Hmm, I would need to know more about your implementation to see what might be wrong. Are you using double precision?

  • @nipunramani
    @nipunramani 8 หลายเดือนก่อน

    Let's fucking gooo, can you also make a discord to discuss these topics?

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน +1

      :D I would really like to discuss these topics with you guys but I don't feel like moderating or owning a discord server currently. I'll think about it again. You can add me on discord though if you want. My handle is the same as my GitHub name.

  • @Saesentsessis
    @Saesentsessis 8 หลายเดือนก่อน

    Big brain

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      I made a few mistakes :(

  • @desine_
    @desine_ 8 หลายเดือนก่อน +1

    NEW VIDEO!

  • @ivuvu4065
    @ivuvu4065 24 วันที่ผ่านมา

    Thanks! I understand more less how L is conserved at minute: 38:30, but how do you apply an external force to the L. I mean the combination of the L conservation and also some forces producing torques. Thanks!

    • @blackedoutk
      @blackedoutk  17 วันที่ผ่านมา +1

      Similar to the linear motion where force is the derivatve of the linear momentum p, torque is the derivative of the angular momentum L. So in both cases, applying forces or torques for a certain time at the center of mass can be accounted for by integrating both of these and adding them to the respective momentum variables.
      If you have an external force that is not applied to the center of mass, you have to apply it to the center of mass and separately compute its resulting torque by using Torque = Cross(point where the force is applied, Force) and apply it to the angular momentum too.
      Does this help? I would touch on this in future episodes, but idk when I will do those

  • @dimitrisgkofas7787
    @dimitrisgkofas7787 8 หลายเดือนก่อน +1

    I have done something like this with joints for objects in java do you want the code to see if it is ok?

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      I can take a look if you want, but I am actually learning these things roughly at the same time as I am making the videos about it. So I haven't implemented joints myself and I am not sure if I can validate your implementation

  • @tempname8263
    @tempname8263 2 หลายเดือนก่อน +1

    tl;dw
    Let me try to make it shorter. Body has linear and angular momentum. Divide linear momentum by mass to get linear velocity. Transform angular momentum into local frame of reference, divide each component by one of 3 angular masses, and transform it back into global reference frame to get angular velocity (which doesn't always ends up aligned with angular momentum, creating interesting dynamics). Or compose it all in it's entirety into a single momentum->velocity transformation, if you so desire, which ends up as a symmetric matrix - matrix that resizes space relatively to some orthonormal basis. Now move your position by vel*time and rotate your rotation by angVel*time.
    The tricky part here is actually calculating next rotation, since it is represented *either* with geometric algebra rotors and bivectors, or using matrices. (And no, euler angles don't count, they are just funny useless parametrization, that can't do anything on it's own)
    Anyway, long story short(er):
    Angular velocity (or momentum) is a bivector - a quantity, where each component is associated with 2 coordinates. Kinda non-diagonal elements in a matrix. But here, instead of linear mapping, they represent oriented quantity from one axis to another one - for example "+5xy" shows rotation around "z" axis.
    Easiest way to turn them into actual rotation is by viewing them through the lense of VGA. In it, vector is used to represent reflection around a plane, and so a composition of two of them gives us a rotative transformation twice that of angle between them. This is called a rotor (in 2d only it's a complex number, in 3d it's quaternion). Composition rules are pretty simple (read left to right): "x*x = 1", "x*y = xy". So "(1x + 0y) * (0x + 1y) = 1xy".
    "1xy" in this case is just a bivector, since vectors were orthogonal to each other, and it represents a +180 degree rotation. But reflections generally don't commute, so composing them backwards will give us opposite rotation "y*x = -1xy", which is -180 degree rotation around z (in 3d).
    Now, these bivectors can be composition-exponentiated, which gives us a rotor (in 2d and 3d you can implement exponentiation using very simple trig, and for other dimensions there is a more general formula). In other words, we just turned rotation direction into a rotation. Compose it with our original rotation, and you're good to go. In any amount of dimensions, at that. Have fun rotating hypercubes!
    Now, in order to render vertices and whatnot, just transform your vector represented as a reflection-operation into a global frame. How? The same exact way we did with local angular mass (which is just an operation converting local momentum into local velocity) and rotation. "[madeupArgument]*reverse(rotation)*reflection*rotation" "[madeupArgument]*reflectionOutsideRotation".
    Anyway, I'll go into more detail and fill in the gaps, if anyone ever reads this and wants to know more. Could as well touch on PGA rigidbody dynamics too, since they are quite elegant and interesting, although their math is a bit too big-brained and not as general purpose, as concepts I discussed.

    • @tempname8263
      @tempname8263 2 หลายเดือนก่อน +1

      tl;dr

    • @blackedoutk
      @blackedoutk  หลายเดือนก่อน +1

      I think covering this in depth needs a bit of time, hence the length of the video. And while I appreciate you trying to explain rotors and bivectors, I don't understand this purely in a short comment. Why don't you make a video about it?

    • @tempname8263
      @tempname8263 หลายเดือนก่อน

      @@blackedoutk Uhhh.. Yeah, making videos is not mine kind of thing. I'd probably just write an article series in couple years, after my current projects are over

    • @tempname8263
      @tempname8263 หลายเดือนก่อน

      @@blackedoutk Just check out materials created by bivector community, to fill in the gaps. My goal was just to give a rough intuition, which those materials on their own do not fully provide. They are more focused on algebraic aspect, and working with transformations as if they're objects (by talking about transformation's invarient subspaces).

  • @aatrox5559
    @aatrox5559 7 หลายเดือนก่อน

    Hi, im currently learning phyiscs, math and i solve c++ problem solving and now i came across few physics simulations and i would love to learn it my self what framework do you use?😊

    • @blackedoutk
      @blackedoutk  7 หลายเดือนก่อน

      Hi, in my game I am using SDL for windowing and inputs, glad for loading the OpenGL functions, Dear ImGui for displying a debug gui and stb for loading images. I have a very basic version of the program on my GitHub in a repo called cg-papers if you want to try it out

    • @aatrox5559
      @aatrox5559 7 หลายเดือนก่อน

      @@blackedoutk Thank you so much, i appreciate the help. best regards :)))

  • @LarsDonner
    @LarsDonner 8 หลายเดือนก่อน

    I've read "this is an initial value problem" in so many papers, I wonder who started it and why it keeps being repeated?

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      Do you think it shouldn't be repeated? I don't know who started it, but to me this seems like the correct term to use

    • @LarsDonner
      @LarsDonner 8 หลายเดือนก่อน

      @@blackedoutk The structure of the problem is so straightforward that calling out its fancy name seems unnecessary, especially when it tends to be only mentioned once and then never brought up again.
      Just a curiosity though, the video is great and I can't wait for the Quaternions to show up!

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      ​@@LarsDonner The reason I mentioned it is so that viewers have something to look up if they want to learn more about it. The problem itself may be easy to understand, but there are a lot of other things associated with it and many different, not necessarily straightforward ways to solve it.
      Though I know what you mean and would probably agree with you in some other cases. I remember seeing the Schur complement being mentioned in the XPBD paper for example and initially thought it was really complicated because it looked like that on Wikipedia. After writing the derivation down step by step though, it turned out to be just some simple equation rearrangements.

  • @bartoszstyperek6306
    @bartoszstyperek6306 8 หลายเดือนก่อน

    At 29:57 you had Matrix1 - Matrix2 * g(r) . Then you just subtracted these Mat1 - Mat2 , ignoring that second matrix is multiplied by g(r). Is this legal? If g(r) is constant then at least it should be M1 - M2*g

    • @bartoszstyperek6306
      @bartoszstyperek6306 8 หลายเดือนก่อน

      Ok, my bad - I can see it's more like [ M1 - M2] * g(r)

    • @blackedoutk
      @blackedoutk  8 หลายเดือนก่อน

      @@bartoszstyperek6306 Yes exactly. But you‘re right, I should‘ve included brackets there, thanks for pointing that out. I was thinking about the rho to be associated with the dV

  • @forinfo8506
    @forinfo8506 8 หลายเดือนก่อน

    omg