Computer Science Canada Car Physics - 2D Straight Line |
Author: | Crashed [ Thu Jan 24, 2008 7:30 am ] |
Post subject: | Car Physics - 2D Straight Line |
Hello CompSci: I'm trying to write a rather simple drag racing simulator, I've checked out various tutorials on the internet and I've purchased a copy of Game Physics for Programmers. Neither of these resources can help me with a problem I'm having right now. The formulas I'm using for my program: F = u * torque * gear ratio * final ratio * transmission efficiency / wheel radius a = F / m v = v(0) + a(t) air resistance = 0.5 * drag coefficient * air density * velocity ** 2 * front area of car For my problem, velocity appears to be measured in KM / H instead of M / S, even know I'm sure all my units are in right. For the sake of testing: torque = 400.0 //Newtons gear ratio = 0.84 final ratio = 3.44 wheel radius = 0.3186 u = 1.0 tranny efficiency = 1.0 time = 1.0 //Seconds, I believe. mass = 1393.0 //Kilograms frontal_area = 2.2 //m^2 air_density = 1.4 //kg/m^3 drag_coefficient = 0.31 To get the maximum velocity at 7200 RPM: v = (2 * pi * wheel radius * rpm) / (60 * gear ratio * final ratio) I do not know what the 2 * pi or 60 is for. v = (2 * pi * 0.3186 * 7200) / (60 * 0.84 * 3.44) v = 117.202742 //KPH!!! v is measured in KPH there! Not only there, but in the rest of my program the current velocity of the car is in KPH and I have no idea why. self.calculate_torque() air_resistance = 0.5 * self.drag_coefficient * self.air_density * self.speed ** 2 * self.frontal_area drive = (1.0 * self.torque * self.gear_ratio() * self.final_ratio * 1.0 / self.wheel_radius) - air_resistance acceleration = drive / self.mass self.speed += time * acceleration self.rpm = self.speed * self.gear_ratio() * self.final_ratio * 60 / (2 * pi) self.loc += time * self.speed At any given time, speed is in KPH units instead of M/S. As a result of that, my air_resistance force is becoming so large by 3rd gear I'm no longer capable of accelerating anymore. Does anyone know what I'm doing wrong? |
Author: | Clayton [ Thu Jan 24, 2008 8:28 am ] |
Post subject: | RE:Car Physics - 2D Straight Line |
If it's in KPH, then just put the number through a conversion function that returns the result of your km/h scalar into a m/s scalar. |
Author: | Crashed [ Thu Jan 24, 2008 8:37 am ] |
Post subject: | RE:Car Physics - 2D Straight Line |
I have tried that, which made my car only slightly faster. The air resistance gets so high in third gear (and 4th, 5th, etc) at about 5,000 RPM that I can no longer accelerate. |
Author: | Crashed [ Thu Jan 24, 2008 8:52 am ] |
Post subject: | RE:Car Physics - 2D Straight Line |
Third gear (1.52 gear ratio) at 5,000 RPM, generating 300 NM of torque, the air resistance and the drive force equal out - so there's no acceleration. |
Author: | md [ Thu Jan 24, 2008 12:19 pm ] |
Post subject: | RE:Car Physics - 2D Straight Line |
You should only accelerate if you increase the RPMs, and unless your simulating an entire engine you would generakky just increase a number somewhere. This seems pretty interesting though. |
Author: | Skynet [ Thu Jan 24, 2008 2:45 pm ] |
Post subject: | Re: Car Physics - 2D Straight Line |
Excellent, someone using real units. Regarding your velocity, I'll restate your equations: The velocity of your car is equal to the angular velocity of your wheels * your wheel radius. This will be in m/s if: 1) Your wheel radius is in m 2) Your angular velocity is in rad/s - this is where the 2*pi/60 term comes from. RPM * 2*pi/60 = angular velocity You also have the gearing of your transmission in there, as your wheels don't spin at 7200 RPM. (gear ratio & final ratio terms) All of your equations seem to be in SI form and your speed will be in m/s, as opposed to km/h. Why do you think it's in km/h For final velocity, your conclusion about air resistance and drive force equaling is correct - this is the limitation on your velocity. Set F_drive equal to F_air and solve for v. There are a few other things you can put in to make it more realistic, but building it from proper physical principles is definitely the way to go. P.S...for your comments, Torque is measured in "Newton-meters" (Nm) |
Author: | Crashed [ Thu Jan 24, 2008 5:35 pm ] |
Post subject: | RE:Car Physics - 2D Straight Line |
The reason why I think it's in KM/H is because the book I'm using, Car Physics for Programmers, basically tells me so. It tells you how to calculate maximum velocity (formula above), and it also tells you the answer for a demo case Vmax = ... = x M /S = y KM / H. I seem to be getting the KM / H, but when I convert I get the M / S. Oh well, I can deal with KM / H fine. What I can't deal with is how strong this air resistance is. I plucked all the right data from the Porsche Boxster S, and hopefully the right formula, and Game Physics for Programmers tells me that the max velocity with factors such as rolling resistance, air drag, etc is somewhere around 260 KM / H, but I'm getting 100 KM / H. What's causing confusion is that their formulas for the rest of the program deals with ODEs and stuff, and it's really just unneeded. I don't know what I am doing wrong, can you suggest anything? |
Author: | Skynet [ Thu Jan 24, 2008 6:19 pm ] |
Post subject: | Re: Car Physics - 2D Straight Line |
When I punch in those numbers you have, I get 83.09. This formula is in m/s, there's no doubt about it. Converting, that's roughly 299 km/h. Solving for v by equating the drag force with the engine force, I get a max velocity of 87.17 m/s, so you're not stopped by air resistance. Input numbers seem right. 400 N-m @ 7200 RPM gives a 405 HP car, which is in the right order of magnitude. To make things easier, I'd suggest that that only time you work in km/h is if you want to display something to the user. Keeping things in m/s through your physics engine will be a lot more straightforward. |