Suddenly Unsmooth Rotation Animation ?HLEP!!!

I’m a fresh beginner.Anyone can help me?

I am making a Cart Game .I want Record my car’s trace.And play the replay.
My idea is :
1:record the car’s position and eulerangle every 5 frames.(about 10 keyframes per second)
2:make the keyframes be curves.(And Question Comes)
Unity Animation cannot save the eulerAngles component.So I had to convert it into Rotation:
Quaternion q=Quaternion.Euler(rot);
then get q.x,q.y,q.z,q.w
3:Set position curves and rotation curves to animation:
animTemp.SetCurve(“”,typeof(Transform),“localPosition.x”,curves[0]);
animTemp.SetCurve(“”,typeof(Transform),“localPosition.y”,curves[1]);
animTemp.SetCurve(“”,typeof(Transform),“localPosition.z”,curves[2]);
animTemp.SetCurve(“”,typeof(Transform),“localRotation.x”,curves[3]);
animTemp.SetCurve(“”,typeof(Transform),“localRotation.y”,curves[4]);
animTemp.SetCurve(“”,typeof(Transform),“localRotation.z”,curves[5]);
animTemp.SetCurve(“”,typeof(Transform),“localRotation.w”,curves[6]);
4:Play the animation

but the rotation animation shape is not smooth:

my animation can be played but it is always shake.
Thanks for anyone who would help me.

If i drag any keyframe’s tangent handle of animation curve,all curve become good.I don’t know why.Of course ,I can’t do this after publish.

Well,I have conquer the problem.
before convert to quaternion,I do the function:
while(rot.x>180){
rot.x-=360;
}
while(rot.z>180){
rot.z-=360;
}