From 410a072c3862481f729c293402ddd49c5ae98769 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 24 Jun 2021 13:49:23 -0400 Subject: (mkosarek) Decent enough discussion of 2d rotational forces --- 2d/rigidbody/rigidbody_2.html.content | 71 ++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to '2d/rigidbody/rigidbody_2.html.content') diff --git a/2d/rigidbody/rigidbody_2.html.content b/2d/rigidbody/rigidbody_2.html.content index 351d544..5ac04a7 100644 --- a/2d/rigidbody/rigidbody_2.html.content +++ b/2d/rigidbody/rigidbody_2.html.content @@ -16,13 +16,82 @@

Rigidbody #2: Rotational Forces

+

+ Now that we have linear forces acting upon the 2D objects in our scene, it is about time we incorporate rotational forces into our simulation. Please keep in mind that I do not go too into depth on why the rotational quantities and formulas are the way that they are. If you are looking for this information, I have linked to some great articles on physics (specifically Chris Hecker's articles!) on the home page. +

-

Explanation

+

What are rotational forces?

+

+ Rotational forces help us to model how an object is rotating around its center of mass. The great part is that they have a lot in common with their linear counterparts: torque (τ) is the rotational equivalent of linear force; angular acceleration (α) is the rotational equivalent of linear acceleration; angular velocity (ω) is the rotational equivalent of linear velocity; moment of inertia (I) is the rotational equivalent of center of mass; and the current rotation of an object is the equivalent of the position of the object. In two dimensions, all of the angular quantities can be defined using a single floating point number (in 3D, this gets a little more complicated). +

+
+
+

The Data Structure

+

+ Rotational forces introduce three new quanities into our Rigid Body data structure: +

    +
  • Rotational Velocity (float): Much like linear velocity, this value defines the rate at which our object is currently rotating around its center of mass.
  • +
  • Rotation (float): Much like position in the linear world, this value describes the current rotation of our object around its center of mass.
  • +
  • Moment of inertia (float): This quanitity defined how much our object wants to rotate around its center of mass. A higher moment of inertia means an object is less likely to rotate, while a lower moment of a inertia means an object is more likely to rotate.
  • +
+ + Adding these three new quanities to the Rigidbody struct from last time, we get someting that looks like this: + + #SNIPPET rigidbody_2/snippet1.cpp + + Now, that's enough for the data side, let's see how we can input some forces into this data structure to make it move. +

+
+
+

The Functions

+

+ When we inputted a force into our system in the first rigidbody example, we simply told the system "apply this force to the whole object over time." With the introduction of the rotational quantities into our model, we now say "apply this force at this particualr point of the object over time." This point is what we'll call the point of application. Our Impulse struct from last time will now look something like this: + + #SNIPPET rigidbody_2/snippet2.cpp + + So what's the big deal about including this point of application? Well, from physics, we get the following formula: +
+

+ + τ = r x F + +
+ + In laymen's terms, this says that the torque is equal to the perpendicular of the force at r, which is the point of application. When you think about this in your head, it makes a lot of sense. For example, if you smack the top of a pencil from the top with your hand, it's not really going to rotate. However, if you smack the top of the pencil from the side with your hand, it is going to rotate a lot. This is because taking the cross product of the end of the pencil (i.e. the point of application) with the force of your hand (i.e. the force acting on the object) is much larger when r is perpendicular to F. + +

+ + One thing to note is that, in 2D, we do not have the cross product, per se. The closest thing we can do is get the vector perpendicular to another vector using the following function: + + #SNIPPET rigidbody_2/tinysnippet.cpp + +

+ + Now that we've calculate torque, we just need to get angular acceleration, which, when differentiated with respect to time, will yield the velocity and position. Angualr acceleration relates to torque according to this formula: +
+
+ + τ = I * α
+ α = τ / I + +
+ + The I in this case refers to the moment of inertia that I mentioned earlier. As you can tell, the larger the moment of inertia, the less like my object is going to be rotating. You can experience moment of inertia with the following example: Grab the middle of a pencil between your index and thumb fingers. Rotate it back and forth, and note how easy it is do so. Next, grab the end of the pencil and do the same thing. Note that it feels slightly more difficult to rotate the pencil now. This is because of moment of inertia! While you can calculate this quanitity (either manually or programatically), you will find the moment of inertia of many simple objects online. + +

+ + With all of this in mind, we're ready for the code that puts it all together!: + + #SNIPPET rigidbody_2/snippet3.cpp +

Live Example

+

+ This demo is much like the one in the first rigidbody example, with the addition of torque. +