views:

116

answers:

4

I originally posted a much simpler (and less helpful) question, and have edited this to be more specific.

This animation from wikipedia shows basically what I want to accomplish, however - I'm hoping to have it flipped around, where it starts progressing more towards the destination and "up" (in this image), and then arcs more directly to the end point. However, I only have access to a starting point and ending point, what I am hoping to do is be able to determine the other points by specifying a "height" (or width, whatever you want to call it), to determine how high the arc actually goes. http://en.wikipedia.org/wiki/File:Bezier_3_big.png (can't post image due to low rep)

I would like to be able to call a function with the start and end points and a height, and have it return all the points along the way of the curve.

Help or direction would be appreciated.

A: 

Apart for the start-point and the end-point you need to describe the ”angle” or curvature of the arc. A Bezier curve can be good but they are usually implemented with longer sequences of points (as the curvature of the arc is defined by the other points in the line). Have a look at http://en.wikipedia.org/wiki/B%C3%A9zier_curve , at the bottom you can find some information about ”Quadratic curves”. I bet a quick google search will give you some implementation examples.

Mikael
A: 

You basically want a bezier curve with three control points - the start point, the end point and another point somewhere in between.

If the start point 1 is ( x1, y1 ) and the end point 2 is ( x2, y2 ) then the vector from point 1 to point 2 is ( dx = x2-x1, dy = y2-y1 ).

A point along the line by an amount along between zero and one is ( x1 + along * dx, y1 + along * dy ).

The vector ( -dy, dx ) is at right angles to the line, so if you want to go off the line by an amount above then the middle point would be ( x1 + along * dx - above * dy, y1 + along * dy + above * dx).

Vary the values of along and above until you find the sort of skewed curve you want.

Pete Kirkham
+1  A: 

Without loss of generality, suppose the ending point is on the x axis and the starting point is above and to the left of the ending point.

Imagine the starting point is at the top of a cliff, and the ending point is at the bottom of a cliff. Imagine you throw a ball horizontally from the starting point, such that gravity will pull it down so that it smacks exactly into the ending point.

That curve seems to have the properties you want. It starts shallow and then increases towards the vertical as the ball accelerates.

By changing the angle at which you throw the ball initially you can make the curve more shallow at the beginning. By changing the strength of gravity you can make it more steep at the end.

Does that curve fit your needs? Finding that curve is a pretty basic physics problem.

Eric Lippert
That curve exactly fits my needs. I've found several examples that relate to bezier curves but, my problem is only having a starting and ending point. I'm not sure if there is a way to calculate the other needed points from just those two to get the desired type of curve.
Frustrated Guy
@FrustratedGuy Typically you do need minimum 4 points for a Bezier curve. Since you know your shape, you _can_ compute the location the two p1,p2 control points. P1 rests on the tangent line with the start point P0 and your "height" determines the distance to P0 along the tangent line. P2 is similar calculation. Function B(t) where t is the time variable would look like: B(t) = (1 - t)^3 x P0 + 3t x (1-t)^2 x P1 + 3t^2 x (1-t) x P2 + t^3 x P3.
MandoMando
@Frustrated Guy: @MandoMando is right; you're going to need at least four parameters to define your curve. In my example, the four parameters are the two end points, the initial angle, and the force of gravity.
Eric Lippert
@Frustrated Guy: Note that in addition to vertical acceleration, you can also modify your curve by adding horizontal acceleration. Finding this curve is still a basic physics problem (e.g. throwing a ball when it is windy), and it is not really much more difficult to calculate. If your start and end points are at the same height, your curve will be symmetrical unless you introduce horizontal acceleration.
Brian