public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var obj = (Quaternion)value; TQuaternion tobj = new TQuaternion() { x = obj.x, y = obj.y, z = obj.z, w = obj.w }; serializer.Serialize(writer, tobj); }
public static TQuaternion Parse(string str) { var sps = str.Trim('(', ')').Split(','); var data = new TQuaternion { x = float.Parse(sps[0]), y = float.Parse(sps[1]), z = float.Parse(sps[2]) }; return(data); }
// Поворот с помощью кватерниона public TVector RotateByQuaternion(TQuaternion Q) { TVector Result = new TVector(Vector); TQuaternion ResultQ; TQuaternion vector = new TQuaternion(0, this); ResultQ = Q.Mult(vector); ResultQ = ResultQ.Mult(Q.Conjugate()); for (int i = 1; i < 4; i++) { Result.Vector[i - 1] = ResultQ.Vec[i]; } return(Result); }
// Поворот на угол вокруг оси (через кватернионы) public TVector RotateByAngleOnAxis(double phi, TVector V) { TQuaternion Q = new TQuaternion(phi, V); Q = Q.Normalization(); TQuaternion ThisVecQ = new TQuaternion(0, Vector[0], Vector[1], Vector[2]); TQuaternion ResultQ = Q.Mult(ThisVecQ); ResultQ = ResultQ.Mult(Q.Conjugate()); TVector Result = new TVector(Vector); for (int i = 1; i < 4; i++) { Result.Vector[i - 1] = ResultQ.Vec[i]; } return(Result); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { TQuaternion tObj = serializer.Deserialize <TQuaternion>(reader); return(new Quaternion(tObj.x, tObj.y, tObj.z, tObj.w)); }