# Interpolation between two Bezier position keys

I need to write a function to interpolate between two Bezier position keys. Each key is defined like so:

struct bpkey {
Point3D ptPos;
Vector3D vTanIn;
Vector3D vTanOut;
float fTime;
};

Point3D TweenKeys( bpkey& pI,bpkey& pT,float fTime );

I think it would go something like this, but I’m not sure:

float fT=fTime/(pI.fTime+pT.fTime);
float fMagIn=pT.vTanIn.mag();
float fMagOut=pI.vTanOut.mag();

return (pT.ptPos*(fT*(fMagIn+fMagOut)));

Does anyone know if that is anything close to correct? Thanks in advance.

I’m sorry, that code should be

float fT=fTime/(pI.lTime+pT.lTime);
float fMagOut=pI.vTanOut.mag();
float fMagIn=pT.vTanIn.mag();

return (pI.ptPos+pT.ptPos*(fT*(fMagOut+fMagIn)));

yet another correction, the line

float fT=fTime/(pI.lTime+pT.lTime);

should be

float fT=fTime/(pT.lTime-pI.lTime);

of course, I would check to make sure the denominator is not zero…