The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Car driving physics

Hey all, I want to write a simple car game with some basic physics. I just want simple acelleration and gear shifting. Maybe attrition later. So I'm looking for some physics topics / formulas to do this a basic level?
Thanks.
NotBeforeMidnight
Thursday, April 19, 2007
 
 
What did your google search on the topic come up with?

Thursday, April 19, 2007
 
 
F=ma and just fake the shifting by playing a different sound.
Bob
Thursday, April 19, 2007
 
 
> just want simple acelleration

For a semi-accurate simulation I'd guess that the relevent formulae are:

* Torque (which varies over the range of rpm)
* a proportional to F (and is F proportional to torque?)
* speed as integral of a over time
* friction or wind resitence (increases with speed)
Christopher Wells Send private email
Thursday, April 19, 2007
 
 
The forums at RaceSimCentral are probably a good place to start.  There are some race sim gamers there who really know their stuff.  They have a forum dedicated to car physics (all the forums seem to be down at the moment, though):
http://forum.rscnet.org/
http://forum.rscnet.org/forumdisplay.php?f=77

Not open source, but there is a race sim that is free and makes an old version of its source available:
http://www.racer.nl/

Here's good online resource regarding car racing physics:
http://www.miata.net/sport/Physics/index.html
Herbert Sitz Send private email
Thursday, April 19, 2007
 
 
But if you really want to keep it simple then Bob's suggestion sounds good.
Herbert Sitz Send private email
Thursday, April 19, 2007
 
 
" F=ma and just fake the shifting by playing a different sound."

Wanted the shifting of the gears to have some effect in the max speed and RPM and so.
NotBeforeMidnight
Friday, April 20, 2007
 
 
Yes, switching gears should affect acceleration.  Lower gears  (i.e, higher gear ratios) transfer more of the torque created by the engine to the wheels.
Herbert Sitz Send private email
Friday, April 20, 2007
 
 
Have a look at the "Physics of Racing Series" (http://www.miata.net/sport/Physics/). Perhaps you might also get some ideas from TORCS, an open source racing car simulator (http://torcs.sourceforge.net/).
vrt3 Send private email
Friday, April 20, 2007
 
 
"Wanted the shifting of the gears to have some effect in the max speed and RPM and so."

Okay, MaxSpeed = 25 * CurrentGear; CurrentRPM = 500 + CurrentSpeed / MaxSpeed * 6000. You can have that.
Bob
Friday, April 20, 2007
 
 
F = ma isn’t bad, but I think you’ll get more realistic effects if your base speed and acceleration on power. Power output in watts of an engine is equal to torque in neuton-meters times engine speed in radians per second. In reciprocating engines, torque is engine displacement in times engine “brake mean effect pressure” (BMEP). BMEP is the average net gas pressure exerted on the pistons which depends on specific engine design (e.g., compression ratio, cam profile, exhaust tuning, turbocharging), but generally has a roughly inverted U shape with a reciprocating internal combustion engine RPM. Unless you’re trying to simulate a specific actual car, just pick a reasonable maximum torque value for the engine displacement you’re simulating and use a parabolic function that places the peak torque at about 70% of redline and 0 torque at 0 RPM. See car enthusiast magazines for some example numbers for redline and peak torque. From this simple model, you can calculate the full-throttle power output of your car at any RPM, and therefore for any gear and road speed. Note that downshifting does not necessarily increase torque, but does increase engine speed and therefore power.

Power necessary to move the car at a given speed = TR + LP + RR + AR. TR = powertrain resistance power. Figure 20% of your power goes to that. LP = lifting power, or the power to climb hills (or power not needed to descend hills). LP = W* V*S, where W = car weight in neutons, V = car speed in meters per second, and S = hill slope as a ratio of change in height (negative for downhill) per unit forward movement. RR = rolling resistance power = CR * W * V, where V = car speed in meters per second, W = weight of the car in neutons, CR = rolling coefficient of friction. I’d use CR = 0.02 for high performance street tires. AR = air resistance power = 0.5 * RHO * V^3 * A * CA. RHO = air density, which is about 1.2 neuton per cubic meter at sea level, V = car speed again, A = the cross-sectional area of your car when viewed head on (in square meters), CA = aerodynamic drag coefficient. Figure CA = 0.25 for an ultra-sleek car, 0.30 for a typical sports car or econobox, and 0.40 for an SUV or pickup.

The terminal speed of a car is the point where power output equals the power-to-move. Any difference between power output and power-to-move is accelerating power (or decelerating if it’s negative). Accelerating power will equal the rate of change in the car’s kinetic energy, E, where E = 0.5 * M * V^2, where M = mass of the car in kilograms, and V is car speed again. Since mass is essentially constant, you can use this relation to calculate your instantaneous rate of speed change (i.e., acceleration) for any accelerating power.

That’s pretty much from memory, but probably good enough to get started coding a game. Your mileage may vary.
Michael Zuschlag Send private email
Friday, April 20, 2007
 
 
The "neuton" of course, is a unit of measure named after the famous physicist Sir Isaac Neuton, who is credited with discovering the subatomic particle known as the "newtron." So you have to ask yourself, are my fisicks better than my speling, and grammer?
Michael Zuschlag Send private email
Friday, April 20, 2007
 
 
I see that http://www.oreilly.com/catalog/physicsgame/ has a dozen or so pages on cars.

But thank to Mr. Zuschlag. Before this, I thought that "neuton" was a measure of figs.
George Jansen Send private email
Friday, April 20, 2007
 
 
Michael, that was a great little blast from the past for me. In the late '70s I was busy trying to figure out exactly what I wanted for an engine rebuild (327 ci from a Corvette being dropped into a '57 Chev Belair Wagon). I wanted decent efficiency, where 'efficiency' was defined as making the most effective use of every drop of fuel (street/stripper). I started with research at the library and by the time I was done I'd bought a VIC-20 for $1000 (!) which I programmed to do all the hard stuff.

In the end, I required only 1 custom-machined part (cam, of course), but found a 'close enough' one from Isky. 25 or so Imperial MPG at 65 MPH, high 14s in the quarter (at <mumble> MPG). If I remember correctly, I should have been able to trade highway MPG for lower quarters and vice versa, but I was very happy with the results.

It's funny how that works. Cars are now just a way to get from one place to another and I program for a living.
Ron Porter Send private email
Friday, April 20, 2007
 
 
"Note that downshifting does not necessarily increase torque, but does increase engine speed and therefore power."

Surely that's not quite right.  1st gear in a car at engine speed of 3500 rpm will have far greater acceleration than 3500 rpm in 6th gear.  I realize the engine itself isn't generating greater torque, but the system of gears and driveshaft will generate far more torque at the wheels in lower gears.

Perhaps I'm wrong, but I think of it as not much different from pedalling a 10-speed bike.  1st gear on 10-speed allows the engine (i.e., me) to create large amounts of torque at the wheel, letting me easily pedal up a steep hill.  10th gear, in contrast, takes the same engine power and generates very little torque at the wheels; it's difficult to start from a dead stop in 10th gear, even on a level surface.
Herbert Sitz Send private email
Friday, April 20, 2007
 
 
It's a combination.  At 1000 RPM (Idle, basically) the engine generates not a whole lot of torque.  So there is an RPM Torque curve, which peaks around 3500 RPM, depending heavily on the engine and its timing and... a lot of factors.  And this is for 4 cylinder engines, 6's and 8's have their own features.

The gears in the transmission let you put out lots of torque but at low speed (like in first gear) or lots of speed but not as much torque (like cruising in fifth gear at 60 mph).

Lots of torque lets you accellerate quickly -- but then you have to upshift before you red-line the engine.  At cruise speed, you only need enough torque to balance wind resistance and rolling resistance to maintain your speed.

"Power drivers" who are thrashing their cars will try to keep the RPM's in the "power band" (2000 to 4000 RPM) as they are accellerating and upshifting.  More efficient drivers will try to keep the RPM's low, and will upshift as soon as they can do so without 'lugging' the engine.

"Lugging" the engine happens when you've upshifted too early, and the RPM's at the new, higher gear are too low (like 1000 RPM), so the engine doesn't have enough torque to accellerate in the new gear.
AllanL5
Friday, April 20, 2007
 
 
Yes, Sitz is correct. The actual torque at the drive axel, or, of ultimate importance, the force by the tire contact patch to the pavement, is proportional to the gear ratio of the current gear. This is something forgotten by those who favor big slow-spinning hulks of engines because they “want lots of torque.” A faster-spinning smaller-displacement engine can put the same force to ground because it can use a higher primary drive gear ratio.

I’ve never reconciled to my own satisfaction the use of torque/force versus power to predict car acceleration. Seems like they should work out to be mathematically the same, but I’m not sure it does. However, I do know that if you computationally model a road vehicle performance using power like I described above, and plug in actual vehicle specifications from the magazines, you get performance very close to that reported by the magazines.

From a power perspective, you accelerate lower at higher road speed irrespective of the gear. I think you can feel that in the seat of the pants when accelerating in any gear: the intensity of the acceleration rolls off with increasing speed, well before you reach the RPM of peak torque or power (except with a very “cammy” engine with an abrupt torque curve, but I’m talking OEM cars). The power perspective says this is because each mph change represents a greater change in kinetic energy. Accelerating from 0 to 10 m/s represents 50 joules per kg of energy to build up to, but accelerating from 20 to 30 m/s represents 250 J/kg. With power constant (assuming the driver picks whatever gear correspond to peak power for the given road speed), it’s going to take five times longer to build 250m J of kinetic energy than 50m J. This is not even including the fact that 20 to 30 m/s you have more drag to overcome than 0 to 10 m/s
Michael Zuschlag Send private email
Friday, April 20, 2007
 
 
I built these pages a few years ago as a test of ASP.Net dynamically generating graphs.  It is also a decent example of the real effects of torque and horsepower.

http://www.smithsquared.net/torquevhorsepower.aspx

I know the site has a few broken links and isn't finished.  Please, no picking on me.

Anyways, the end result is that torque numbers are totally irrelevant to real world acceleration unless you are holding almost every other variable constant.  Horsepower and weight are a very good predictor of acceleration, regardless of almost any other factor.  And, in every case where torque is a useful predictor of performance, horsepower is also a useful predictor of performance.
JSmith Send private email
Friday, April 20, 2007
 
 
"horsepower is also a useful predictor of performance"

Isn't horsepower a MEASURE of performance? Isn't that the point of it?

So what you're saying is the same as saying that velocity is a useful predictor of speed.
2CV
Saturday, April 21, 2007
 
 
In my post, I meant performance as a measure of how a vehical actually performs in a contest.  As long as it isn't a "horsepower competition", horsepower isn't a measure of performance.  Things like elapsed time and top speed are the measures that are usually used to judge the top performer at a contest.

What I tried to point out was that if two vehicles the same weight line up side-by-side and you know the peak horsepower of both and the peak torque of both, the horsepower figures will give you an excellent indication of which vehicle will likely perform better.  However, the torque figures will only have a loose correlation to the outcome of the contest.  The link I gave demonstrates that fact.

Also, almost everywhere torque is a useful measure, horsepower is at least as good.  For example, a lot of people like to use the phrase "low end torque".  Well, "low end horsepower" isn't a phrase that is used very often, but it would be just as useful to express the same characteristic.
JSmith Send private email
Saturday, April 21, 2007
 
 
Typically "Performance" in a car is related to the Accelleration figures (Time to 60 mph at full accelleration). 

I think the post was that Horsepower is related to Accelleration better than Torque is related to Accelleration.

So it wasn't saying that "power is related to power".
AllanL5
Saturday, April 21, 2007
 
 
Once you get the straight line acceleration going, you can move on to the tire/road interface, and deciding how much side load the tires can take before they start to slide. Any who drives knows that depends on acceleration/braking.
Peter Vanderwaart
Sunday, April 22, 2007
 
 
So when you actually drive the car and push the acellerating pedal, what's the effect on the system?

Thanks.
NotBeforeMidnight
Sunday, April 22, 2007
 
 
Ben S Send private email
Monday, April 23, 2007
 
 
> 1st gear in a car at engine speed of 3500 rpm will have far greater acceleration than 3500 rpm in 6th gear.

<Smart Ass>
In both cases the acceleration will be 0  ;-)
</Smart Ass>
IanH. Send private email
Tuesday, April 24, 2007
 
 
"horsepower is also a useful predictor of performance"

'Isn't horsepower a MEASURE of performance? Isn't that the point of it?'

Horsepower as a predictor of of performance is limited to top speed.  Given the weight of a car, its drag coefficient, and friction in the system, you could use horsepower to calculate  its top speed.

Horsepower is technically not going to tell you anything about acceleration.  Acceleration depends entirely on torque.  But an engine with tiny horsepower and relatively small torque could have great acceleration if the gearing ration was high enough.  Gearing operates on something like the "lever principle' to magnify torque produced at the engine (i.e., "at the crank") to higher torque at the wheels, where force is applied to actually move the car forward.

Horsepower is a good rule of thumb for acceleration because cars with higher horsepower generally have higher torque.  This is just a rule of thumb, though.  For example, diesel engines generally have relatively low horsepower but can produce prodigous torque. 

Also, Japanese cars (e.g. Honda) often have relatively high horsepower engines with relatively low torque.  The low torque would doom them to low acceleration, but they make up for this by using higher gear ratios that give better acceleration.  These higher gear ratios require higher engine rpm to attain given speeds, but it's not a problem because they're small high-revving 4 cylinder engines.  Here's a comparison of horsepower and torque numbers for Porsche Boxster and Honda S2000 from a few years ago.  Notice that the Boxster has lower hp but higher torque, while both cars weighed roughly he same.  The Boxster acceleration was actually faster than than the S2000:

Boxster:
    201 hp at 6000 rpm, 181 lb-ft at 4500 rpm.

S2000:
    240 hp at 8300 rpm, 153 lb-ft at 7500 rpm.
Herbert Sitz Send private email
Tuesday, April 24, 2007
 
 
> 1st gear in a car at engine speed of 3500 rpm will have far greater acceleration than 3500 rpm in 6th gear.

'<Smart Ass>
In both cases the acceleration will be 0  ;-)
</Smart Ass>'

Well, yeah, acceleration is of course 0 at constant rpm, but give me a break on context here.  And use some calculus to calculate acceleration at precise point where an accelerating car's engine rpm rise through 3500 rpm.
Herbert Sitz Send private email
Tuesday, April 24, 2007
 
 
"Horsepower is technically not going to tell you anything about acceleration.  Acceleration depends entirely on torque.  But an engine with tiny horsepower and relatively small torque could have great acceleration if the gearing ration was high enough."

No, it can't.  You won't be able to gear it up that far without limiting the top speed to below the current speed (and therefore, negative acceleration) or blowing the engine.

Did you look at my charts?  I ran a scenario similar to what you describe.  A 50 ft-lb torque vehicle beats a 100 ft-lb of torque vehicle at ALL speeds, right from the start.  The only time your argument works is if you put rediculous restrictions on the comparison, like telling one driver they can't shift when they obviously should.
JSmith Send private email
Wednesday, April 25, 2007
 
 
"Did you look at my charts?  I ran a scenario similar to what you describe."

Thanks, reading your site and a few others showed me that a lot of what I've thought about hp and torque for a long time are just plain wrong.  A low torque engine just naturally requires a different kind of gearing than a high torque engine, but if their hp is the same then acceleration should be the same.  Right?  So explanation of S2000 having higher hp than Boxster but not being faster has mostly to do with the shape of their engine's hp curves, not with fact that S2000 is a lower torque engine.  Does that sound right?

"A 50 ft-lb torque vehicle beats a 100 ft-lb of torque vehicle at ALL speeds, right from the start.  The only time your argument works is if you put rediculous restrictions on the comparison, like telling one driver they can't shift when they obviously should."

You're losing me here.  Assuming the engines are paired with appropriate gear boxes, why wouldn't the answer to which accelerates faster not depend on the hp curves of the respective engines?
Herbert Sitz Send private email
Wednesday, April 25, 2007
 
 
I assume shape of torque curve also figures in, but for 50 lb-ft and 100 lb-ft I'll assume their torque curves have identical shapes. . . .
Herbert Sitz Send private email
Wednesday, April 25, 2007
 
 
Torque is a measure of work. Move 5501b through a vertical distance of 1 foot to get 550 ft-lb of work. Commonly expressed as torque when referring to twisting forces (levers, output shafts, etc.). It doesn't matter how long it took to get the job done, the work is the work.

Horsepower is a measure of power. Power, in this sense, is all about how long it takes to get the work done. Lift that 550lb weight 1 foot and do it in 1 second-- voila, 1 horsepower. Horsepower is a measure of work over time. If it takes you twice as long to get the job done, it doesn't change the fact that you got there, but when's coffee? :)

The reason that horsepower is a good predictor of the common measures of car performance is that it is a simple measure of how much work can be done in a given time. More  horsepower makes it possible to do the same work (move 2 tons through the distance of 1/4 mile) in less time.

A great write-up can be found at http://vettenet.org/torquehp.html
Ron Porter Send private email
Thursday, April 26, 2007
 
 
That characterization of torque seemed wrong to me, doesn't fit with what I remember from college physics.  Torque is a measure of force applied at a distance.  It is _not_ the same as work, since torque can be applied when there is no work done, i.e., when nothing moves.  Here's a good clarification:

"Notice that the units for torque and work are basically the same, yet torque and work are two different things. Torque is a force that causes a rotation, which means that it does not actually cause an object to move along a distance. Therefore, torque is not work."
http://craig.backfire.ca/pages/autos/horsepower

The characterization of power as being "all about how long it takes to get something done" seems just slightly  misleading also.  It's a measure of the "rate" at which work gets done, so in addition to being about how long it takes it's also very much about how much work gets done.  A little picky, maybe, but these are precise concepts.
Herbert Sitz Send private email
Thursday, April 26, 2007
 
 
Think about horsepower as the potential to do work.  More horsepower means that more work can be done in the same amount of time.  Torque is more situation specific.  It always needs some qualifier to makes sense.

For example, if you go out and buy a 2HP electric motor, you pretty much know what it can do.  However, if you were looking for a motor to power a cordless drill and knew it needed 500 in-lbs of torque to drive deck screws, you would still need to define at what rpm in order to choose a motor.  A $1 toy car motor can make 5000 in-lbs of torque if it is geared down to 0.005 rpm.  That $1 motor is never going to be rated at 2HP no matter what you connect it to.
JSmith Send private email
Thursday, April 26, 2007
 
 
Thanks for the clarification, Herbert. Precise definitions are a good thing.
Ron Porter Send private email
Thursday, April 26, 2007
 
 
I might be wrong, but from what I remember torque is a vector (i.e has a directional component) where as work is a scalar (ie no directional component).
Jussi Jumppanen
Friday, April 27, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz