This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
salvin francis
Bartender
Posts: 1263
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...

 
salvin francis
Bartender
Posts: 1263
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1263
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic