 # Simple 2d interpolations between two 4-vertices shapes

Hello,

I have an interpolation question:

This happends in 2D world.

I have two “rectangulars” (not necessarily exactly 90 degrees) that define two extreme positions. Based on these values, I need to find the vertices of “rectangular” positioned between them (linear).

What would be the most appropriate way to interpolate between these two shapes, like the red “rectangular” on the illustration attached (based on Y value of vertice A for example)

Thanks a lot
M

Hi, you can simply interpolate the vertices using any of the following

``````Type ofInterpolateCosine(const Type& y1, const Type& y2, float pct);
Type ofInterpolateCubic(const Type& y0, const Type& y1, const Type& y2, const Type& y3, float pct);
Type ofInterpolateCatmullRom(const Type& y0, const Type& y1, const Type& y2, const Type& y3, float pct);
Type ofInterpolateHermite(const Type& y0, const Type& y1, const Type& y2, const Type& y3, float pct);
``````

Where `Type` can be a number or glm::vec or ofVec

thus,

``````for(int i = 0; i < 4; i++){
interpolatedPos[i] = ofInterpolateCosine(fixed_pos_1[i], fixed_pos_2[i], interpolationAmount);
}
``````

where `interpolatedPos, fixed_pos_1, fixed_pos_2[i]` are vectors or arrays with teh vertices, all with size at least 4 and `interpolationAmount` is a float between 0 and 1 which if it is 0 it returns the first parameter and if 1 the second, otherwise the interpolated value.

If you want to do this with a linear interpolation you can use `ofLerp` but you will need to do it for the components of the vertices (x, y and z)

Hello,

thanks for the answer!
Well I do want to make it linear as on the picture. It’s a displacement in space between two masks for projection

So in this case I need to work with individual coordinates of individual vertices for that ? M