- Home /
Sine Wave Without the SIne Function?
Hi there, Is there a formula for the rate of acceleration/decay of a sine wave? Namely, if you set up a cube, place it at 0,0,0 and then applied the return value from the Sine function (incrementing 0 deg - 90 deg values as the angle argument * a 1 unit radius) to the cube's x position it would move back and forth from -1 to 1 decelerating exponentially before it reached both -1 and 1. Is there a formula that could be used to calculate and express the exponential decay in speed as a negative force instead of using the Sine function?
Answer by elenzil · Mar 19, 2019 at 06:29 PM
a dynamic simulation of a spring will produce the spring's displacement as a sine function of time. the basic formula there is the restorative force is negatively proportional to the spring displacement. then you integrate that w/r/t time however you like.
here's a spreadsheet showing that, with basic euler integration.
Answer by kramazeek · Mar 20, 2019 at 04:50 AM
Thank you, elenzil. I believe that may be what I'm after but I'll have to play around and see. Much appreciated!
Answer by timoffex · Mar 22, 2019 at 07:43 PM
If I understand the question, you are asking whether you can create sinusoidal movement using forces. The answer is yes. You still have to use the sine function because if an object's position at any time t is sin(t), then its acceleration is -sin(t).
Here are two pieces of code that will produce very similar motion (assuming no friction, no other forces, no obstacles):
// Movement by changing transform.position.
void FixedUpdate()
{
float t = Time.time;
transform.position = Mathf.Sin(t) * Vector3.right;
}
// Movement by applying a force.
Rigidbody rigidBody;
void FixedUpdate()
{
float t = Time.time;
float acceleration = -Mathf.Sin(t); // second derivative of position
float force = acceleration * rigidBody.mass; // force = mass * acceleration
rigidBody.AddForce(force * Vector3.right);
}
Acceleration is defined to be the second time derivative of position. Using this requires some basic calculus, but it will allow you to write any motion in terms of forces just by following the two definitions:
1. Acceleration is the second time derivative of position (can be written symbolically "a(t) = (d/dt)^2 x(t)").
2. Force is mass times acceleration (a.k.a. "F = ma").
Your answer
Follow this Question
Related Questions
Top down wasd movement dependent on rotation of the character - Mathematical problem!!! 2 Answers
Trying to obtain sine/cosine by angles giving me imprecise values 1 Answer
I can't find cossine. 1 Answer
Math - Changing the frequency of a sine wave in real-time 1 Answer
Looking at a target in 2D 0 Answers