-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuaternion.cs
More file actions
26 lines (24 loc) · 783 Bytes
/
Quaternion.cs
File metadata and controls
26 lines (24 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
namespace OrthoGraph
{
public struct Quaternion
{
public float W {get;}
public float X {get;}
public float Y {get;}
public float Z {get;}
public Quaternion(Vector3 axis, float angle)
{
Vector3 rotateVector = Normal(axis);
float Sin = (float)Math.Sin(angle / 2);
W = (float)Math.Cos(angle / 2);
X = rotateVector.X * Sin;
Y = rotateVector.Y * Sin;
Z = rotateVector.Z * Sin;
Vector3 Normal(Vector3 v)
{
float length = (float)Math.Sqrt(Math.Pow(v.X, 2) + Math.Pow(v.Y, 2) + Math.Pow(v.Z, 2));
return new Vector3(axis.X / length, axis.Y / length, axis.Z / length);
}
}
}
}