|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Acceleration and Velocity functions for C++?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
4.0ghz
|
I am trying to write a C++ program that will uses acceleration and time to calculate velocity and position. Is there a library of functions that I could include to do these calculations for me, or will I have to write my own functions to calculate position and velocity in relation to acceleration and time?
__________________
|
|||||||||||||
|
|
|
|
#2 (permalink) | |||||||||||||
|
Programmer
|
I don't know of any standardized physics libraries for c++, at least none outside of physics engines intended for games and such.
There are probably some homebrew libraries out there that you could use (I generally just google what I'm looking for to find that sort of thing) but it would also be pretty easy to make your own if all you need is basic acceleration/velocity stuff.
__________________
"He attacked everything in life with a mix of extraordinary genius and naive incompetence, and it was often difficult to tell which was which." Douglas Adams
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
Off By 340 Undecillion
|
I don't know C++ that well, but Going from acceleration and time to velocity and position are just a couple of simple algebraic equations in one dimension, and its not that hard to expand it to three. If your inputs for accel and time are just two numbers, then, assuming that both position and velocity are initially at 0:
Velocity = Acceleration * Time Position= 1/2 * acceleration * (Time^2) If velocity and position are not initially 0 then Velocity = (Acceleration * Time) + InitialVelocity Position= (1/2 * acceleration * (Time^2)) + (InitialVelocity * Time) + InitialPos
__________________
Congratulations! You have found the secret text! You get a cookie.
|
|||||||||||||
|
|
|
|
#4 (permalink) | |||||||||||||
|
New to Overclock.net
|
I can write it with Java, but it should be similar, so maybe you can translate it and TBP already gave the formulas already.
Acceleration = Change of Velocity / Change of Time With this, you cannot be wrong, so then you don't have to think about any other possibilities. I think you need to write your own functions for it. If you need help, I can help you. C++ is similar to Java, so I know I can help you there. It might be annoying, since if there are no constants for each of them, you'll have to make the program a little more complicated though. Since you could be finding acceleration, velocity, or time.
|
|||||||||||||
|
|
|
|
|
#5 (permalink) | ||||||||||||||
|
The Project Keeper
|
Quote:
__________________
|
||||||||||||||
|
|
|
|
#6 (permalink) | ||||||||||||
|
110100001101001111000
|
All you have to do is make two methods for each one. They'll both have the same name, but can take in different inputs (known as polymorphism).
Code:
// this method would compute the case of v0 = 0
double[] findPosition(double time, double acceleration){
}
//this method would take care of the other case
double[] findPosition(double time, double acceleration, double initialPos, double intialVelocity){
}
__________________
|
||||||||||||
|
|
|
|
#7 (permalink) | |||||||||||||
|
Database Developer
|
http://www.mathtools.net/C_C__/Calculus/index.html
Try that, you should be able to take the derivatives / integrals. f(x) = pos. f'(x) = vel. f''(x) = acc.
__________________
A fan of anything which uses AES, .NET, Relational Databases, RAID arrays, water cooling, HSDPA, GPS, x64 or a BMW engine.
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|