Reputation: 1482
I am developing a game in C#/.NET (Windows Forms). While playing the game, there is a scenario where an object moves from a point to another point (from left to right). The co-ordinates of the point on the right side are fixed. However, the position of the object (to be moved to right) is not known in advance and hence its co-ordinates are not known in advance, so we can't have a hard-coded path.
I want to generate a path which moves an object from a left point to a right point in a curved manner (like we throw birds in Angry Birds), not in a straight manner.
Below is the image which may help you to understand the scenario.
Is there an algorithm or any API to perform these kind of tasks?
Upvotes: 0
Views: 748
Reputation: 1482
I found a simpler solution. Using a Bezier curve transform, I can generate the path in the manner I want.
Upvotes: 0
Reputation: 6159
You need to travel an arc of a non-canonical ellipse. You will find some intersting ways to achieve that if you read the Wikipedia article Ellipse, but this should get you started:
'a' and 'b' are your radiuses.
So now just refactor the formula to isolate X and refactor again to isolate Y...
Upvotes: 1
Reputation: 1353
You can compute the physical trajectory of your object. The simple formula, for what you are looking for, is the movement of some object with an initial speed and subject to gravity without drag nor wind. This trajectory is a parabola.
Given the initial speed and gravity, the path is fixed. You can solve the trajectory equation to get the target x,y or the position of your object at some time after the throw.
Upvotes: 2
Reputation: 42450
This isn't too difficult to do. When the object needs to be moved, first get its coordinates (by this point you will know it). Use the equation of projectile motion to get an equation for its path, and then move it along that path.
Upvotes: 1