# polygon morphing

## Recommended Posts

Merick Zero    151
I know this is probably a simple graphing problem, but it's been so long since I've had to use any of this that what I remember from my high school math classes has gotten kinda fuzzy and I'm not really sure where to begin to look for an answer. I've got a table that's basically just a list of x,y coordinates. When I pass this table to my polygon drawing function it goes through the list and draws a line from one point to the next, connecting back to the first point when it reaches the end. What I'd like to do is make a function that can take two of these tables and display an animation of the first polygon morphing into the second. For example, if one table had the first point at x1,y1 and the other had the first point at x2,y2 how could I find the location of the point for the current animation frame based on the max number of frames?

##### Share on other sites
skalco6    181
linear interpolation

x1' = x1 + alpha * (x2 - x1)

alpha as to be in the range of [0,1]
normalize your current frame like this: alpha = currentFrame / frameCount

##### Share on other sites
Merick Zero    151
Thanks! My morphing function works perfectly after plugging that formula into it.