ok thanks so much. I will give you positive feedback!
Printable View
ok thanks so much. I will give you positive feedback!
Nice catch, among us all, you were the most careful when reading the OP's posts. Anyway, we managed to establish that the OP wanted to simulate sinusoidal movement along x=-90 deg (see image in one of my posts), without being necessarily physically correct about every detail.
Now, although the thread has been marked resolved, if you have some suggestions how to model this in terms of forces, I'd love to read them.
A sine motion is usually the result of an elastic force (a spring): The further you are from the origin, the stronger the force.
So, if you put a solid on a spring, on a cart, the cart moving along the x axis at constant speed (and no external force), you'd have that motion.
It has crossed my mind, but at the first moment I got a bit confused by thinking that a moving source of a spring force would eventually cause the spring force to be at an angle to the x-axis - but, of course, you're right; now that I look at it afresh, it only takes for the object to (1) initially have a non-zero x-velocity component (since it starts at the rest position - but not in the rest state), and (2) have the same y-velocity component as that of the spring force source.
So you want to fit a sine curve between two points on a line and then you want an object to trace the curve path at constant speed, right?
First consider an "ordinary" sine curve along the x-axis oscillating in the y-direction. In its most general form it looks like this,
y = A*sin(B*x + C)
where A is the amplitude, B is the frequency and C is the phase.
But for simplicity set A=B=1 and C=0 and get,
y = sin(x)
That's the curve the object follows from some point on the x-axis where y=0. (the x-value must be a multiple of PI). The curve is followed in the negative x-direction until x=0 (and y=0).
If the object is somewhere on the x-axis, say at X, the corresponding y-value is at Y = sin(X). Now say the object moves a small step R away from X,Y along the curve path, what are the new x and y values,
new_x = ?
new_y = ?
Well what's the direction the object must follow from its current position at X,Y to go a length R along the curve? You get an approximation by derivation,
y = sin(x)
dy/dx = y´= cos(x)
So
dy = cos(x) * dx
So say the object goes a length R in the dy/dx direction, what's the relation between those? Well according to Pythagoras it's,
R^2 = dx^2 + dy^2
Inserting dy gives,
R^2 = dx^2 + (cos(x) * dx)^2
and solving for dx gives,
dx = R / sqrt(1 + cos(x)^2)
Since the object goes in the negative x-direction you have,
new_x = X - dx
and with dx inserted,
new_x = X - R / sqrt(1 + cos(X)^2)
To get the new_y it's best to simply use new_x like
new_y = sin(new_x)
because this gives you an exact y-value on the sine curve.
-----
That's the principle now it's just to adapt it to your problem. :)
The A, B and C parameters are used to exactly describe the sine shaped "road" the object should follow. The formulas must be derived anew to include these parameters. Then also the coordinate system must be rotated so the sine "road" gets the wanted "angle". So you must set up a rotations matrix to transform the x and y coordinates to the rotated sine curve. Alternatively you derive the formulas for the rotated coordinate system directly.
You must also get a grip on the R constant. It's the length the object goes in a certain period of time so it's speed related. But it must be small because it's really a dr (since it's related to dx and dy).
@OP:
Definitely check out nuzzle's post:
The solution I proposed, assumes that there is a constant component of the object's velocity (y-velocity in your setup), and calculates (x, y) as a function of time. This means that, along the path the object will slow down on curved sections, and accelerate on the approximately straight parts of the path (since they are angled to the y-axis).
On the other hand, nuzzle's approach is based on the current location of the object, and the distance R the object incrementally travels with each step. If you treat this distance as so small that the motion can be considered linear, then you can, theoretically, make your object move at constant speed along the sinusoidal path.
I've been away from codeguru for a few days, and so missed your post... sorry about that.
Unfortunately, I don't really have much time at the moment, but if I get the chance in the near future, I'll write you something that will model something reasonable. :)
The difficulty with the OP's post is that there are few things that behave in the manner that the OP is requesting. Perhaps looking at a birds-eye view of the path of the weight on a pendulum in a vacuum, mounted on a platform perpendicular to the direction of travel of the platform (the platform traveling at 3m/s). But then more questions appear... What frequency should the pendulum have? What amplitude should the pendulum have?
I guess my real question to the OP is what is the reason for the oscillation that he wants to model?
One can ask - why the sine curve?
Is it a path the object follows of its own free will very much like a car travelling along a road, or is it a trajectory the object follows because it's subject to some kind of external force field?
I assumed the former and took a differential geometry approach. At any point (x,y) the object has access to a direction vector (dx, dy) as it travels and if it adjusts its direction often enougth it will follow the prescribed sine shaped path from start to goal.
In fact it's possible to know how often it must adjust directions. It must do that at least twice for each period of the sine curve it follows. The Sampling Theorem states that. But the more often it adjusts the closer it will follow a perfect sine of course.