my dog learned polymorphism*
The moose likes Game Development and the fly likes Here is how to plot a curve between two points.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Here is how to plot a curve between two points...." Watch "Here is how to plot a curve between two points...." New topic
Author

Here is how to plot a curve between two points....

salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Hi,

This is not a question, but an answer,
An answer to any one who wants to move an object from point A to point B in a curved way,
An answer to any one who wants to plot a curve from point A to point B

here goes :

The answer to this is Bezier Curve

http://en.wikipedia.org/wiki/B%C3%A9zier_curve


well, i know the content there is way over our heads (at least mine ) but i found one equation there that suited my requirement:

Quadratic Bezier curves
B(t) = (1-t)^2*p0+2(1-t)t*p1+(t^2)*p2

I know it sounds gibberish but let me break it down....



looking at this:


when t=0, this is what happens...



when t=1, this is what happens...


So, there you go...
Happy game development

check out the icons animated in my site using this equation ...


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

in this code:


(startX,startY) is the starting point coordinate,
(endX,endY) is the ending point coordinate,

and (bezierX,bezierY) is the control point which governs the curvature of the curve,
think in this manner, if this point is farther away, then the curve is more steep..
if this point is closer then the curve is less steep.

salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Another great equation is the "ease out":

where t is from 0 to 1.

int x = (int) ((1 + Math.cos(Math.PI + t * Math.PI)) / 2);

check the curve when x varies from 0 to 1
http://www.wolframalpha.com/input/?i=plot[(1+%2Bcos(PI+%2B+x*PI))%2F2%2C+{x%2C0%2C1}]

its a slow transition followed by a fast transition followed by a slow transition.
like the way a ball rolls...

try animating an object with the x value varying as per the equation and check the output...



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Here is how to plot a curve between two points....