|
-
Feb 10th, 2010, 07:25 PM
#1
Gravity calculations in a 3D world.
Hey.
I'm having troubles expressing myself this evening so I hope I make sense, if not, please do tell.
Alright so I'm working on a 3D game as a part of some university coursework.
In this game I have simple gravity, pulling objects straight down.
Currently, gravity is only applied to an object if it is in freefall. As soon as it hits the ground, I do not apply any gravitational pull on it unless it "stops" being on the ground.
I would like to change this. I would like to calculate the resulting force to be applied to an object given the slope of the surface it is standing on. (In other words, an object standing on a completely flat surface would be at rest, while an object standing on a steep slope would slide down).
I hope this makes sense.
The problem:
I have a vector defining the gravitational force (straight down) for an object.
I have another vector that is the normal for the plane directly underneath the object.
From this, I must somehow calculate the resulting force on the object.
I've been at this problem for the entire day, but I just cant figure it out
-
Feb 10th, 2010, 10:14 PM
#2
Re: Gravity calculations in a 3D world.
There are two ways to do this. I'll give the one that isn't insanely cool and how physics simulators often really work, since it's much more complicated.
Suppose your object just started to touch the plane. Gravity is making it have a force straight down. Since the object can't go directly through the plane, if this downward gravitational force were unbalanced, the plane would have to move. However, the plane does not move, so the downward force on the plane must be exactly canceled by an upward force. What direction is the force the plane is exerting?
First, let's assume the plane is frictionless. In that case the plane can only exert a force in the direction of its normal. (If it could exert any amount of force perpendicular to its normal, there would be friction by definition, i.e. a resistance to moving along the surface in that direction.)
Now comes the trick. Decompose the force due to gravity into two components: one (anti-)parallel to the plane's normal, and one sloping down the plane. The downward sloping component will be in the normal-gravity plane. This picture shows approximately what I mean, though H should be in the other direction.
For the plane to not move, the force it exerts along the normal must balance the normal component of the gravitational force. There will be a leftover, unbalanced downward sloping component. This is the component of force your object will ultimately feel. You can draw out the situation and determine the magnitudes of these components with trig.
Algebraically...
g = gravitational constant
<0, 0, -mg> = Fg = gravitational force vector on object of mass m
N = normal vector of plane; assumed to be a unit vector
theta = angle between Fg and N = arccos(Fg dot N / (|Fg||N|))
Fg = Fg_N + Fg_S = decomposition of Fg into force along normal and along slope
|Fg_N| = |Fg| cos(pi-theta) from trig
|Fg_S| = |Fg| sin(pi-theta) from trig
Fn = -Fg_N = normal force due to plane, which cancels normal force due to gravity
F = net force on object = Fg + Fn = Fg_N + Fg_S - Fg_N = Fg_S, meaning the object just slides down.
To actually compute F, you'd cut the above simplification slightly short:
Fg_N = -|Fg_N|*N since Fg_N is anti-parallel to the normal
=> Fg_N = -|Fg|cos(pi-theta)*N
=> F = Fg + Fn = Fg - Fg_N = Fg + |Fg|cos(pi-theta)*N
Since you know the normal vector N, Fg is simply down, and theta can be calculated from the dot product as above, you've found the force on the object.
If this were in 2D the form of the answer would have been simpler, something like "just take the cos of theta", but in 3D the vectors need to be used to keep you from having to convert in and out of a plane.
Last edited by jemidiah; Feb 10th, 2010 at 10:19 PM.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Feb 10th, 2010, 10:18 PM
#3
Re: Gravity calculations in a 3D world.
It occurs to me that the cos(pi-theta) bit can be simplified, but I'll leave that up to you. It's your homework, after all .
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Feb 11th, 2010, 09:40 AM
#4
Re: Gravity calculations in a 3D world.
Thanks, that was really helpful!
How would I define friction on the plane, to keep objects from sliding on really flat surfaces?
-
Feb 11th, 2010, 06:42 PM
#5
Re: Gravity calculations in a 3D world.
There are two types of friction on the plane, static and sliding. I'll discuss static, which occurs if the object isn't yet sliding. You can ignore sliding and just use this formulation if you want whether or not the object is sliding or staying still relative to the surface, though it'll be a bit less realistic.
Static friction opposes forces along the plane up to a certain threshold. After the force along the plane gets too strong, static friction maxes out in magnitude and only resists movement instead of entirely stopping it. Usually the maximum magnitude of static friction is taken to be proportional to the magnitude of the normal force an object is exerting--if you push hard on an object, it's harder for it to slide along the plane. The constant of proportionality, c_static, is called the coefficient of static friction. That is, |F_static| <= c_static*|Fn|.
In your case, the plane would exert not only a normal force to entirely balance Fg_N, but also a sliding force to entirely or partially balance Fg_S due to static friction. Say Fp is the force the plane exerts on the object. The force Fp is then Fn + F_static. The net force the object feels would then be F = Fg + Fp.
If the sliding force due to gravity on the object is in magnitude less than or equal to the maximum opposing force due to static friction, static friction will exactly match that sliding force to entirely oppose it without causing the object to slide uphill. Algebraically,
If |Fg_S| <= c_static*|Fn|, then |F_static| = |Fg_S|
Otherwise, the magnitude of the opposing force due to static friction simply takes on its maximum. This won't entirely balance the sliding force of the object, so it will indeed slide--thought somewhat more slowly than if friction didn't exist. Algebraically,
If |Fg_S| > c_static*|Fn|, then |F_static| = c_static*|Fn|
Since F_static opposes Fg_S, we can compute F_static with
F_static = |F_static| * (-Fg_S) / |Fg_S|
If you back substitute all of these and use the formulas I listed in the previous post with any modifications needed due to this extra effect, you'll be able to calculate the net force on the object, figuring in static friction. The coefficient of static friction is a property of the surface material you're working with. It's higher for rougher surfaces. They're usually something like 0.3 to 1; tweak to your preference.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|