public static string ToMatlab(GridVector3[] array) { string s = "["; for (int i = 0; i < array.Length; i++) { s += array[i].X.ToString("F2") + " " + array[i].Y.ToString("F2") + " " + array[i].Z.ToString("F2") + ";" + System.Environment.NewLine; } s += "]"; return s; }
public static GridVector3 Normalize(GridVector3 A) { double mag = Magnitude(A); return new GridVector3(A.X / mag, A.Y / mag, A.Z / mag); }
public static GridVector3 Scale(GridVector3 A, double scalar) { return new GridVector3(A.X * scalar, A.Y * scalar, A.Z * scalar); }
public static double Magnitude(GridVector3 A) { return Math.Sqrt((A.X * A.X) + (A.Y * A.Y) + (A.Z * A.Z)); }
public static GridVector3 FromBarycentric(GridVector3 v1, GridVector3 v2, GridVector3 v3, double u, double v) { double x = (v1.X * (1 - u - v)) + (v2.X * u) + (v3.X * v); double y = (v1.Y * (1 - u - v)) + (v2.Y * u) + (v3.Y * v); double z = (v1.Y * (1 - u - v)) + (v2.Y * u) + (v3.Y * v); return new GridVector3(x, y, z); }
/// <summary> /// Returns dot product of two vectors. Input is rounded to 2 decimal places because of problems I had with double size limit /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <returns></returns> public static double Dot(GridVector3 A, GridVector3 B) { /* double AX = Math.Round(A.X, 3); double AY = Math.Round(A.Y, 3); double BX = Math.Round(B.X, 3); double BY = Math.Round(B.Y, 3); */ double AX = (double)(float)A.X; double AY = (double)(float)A.Y; double AZ = (double)(float)A.Z; double BX = (double)(float)B.X; double BY = (double)(float)B.Y; double BZ = (double)(float)A.Z; return (AX * BX) + (AY * BY) + (AZ * BZ); }
public static double Distance(GridVector3 A, GridVector3 B) { double dX = A.X - B.X; double dY = A.Y - B.Y; double dZ = A.Z - B.Z; return Math.Sqrt((dX*dX)+(dY*dY)+(dZ*dZ)); }
public PositionNormalTextureVertex(GridVector3 pos, GridVector3 norm, GridVector2 tex) { Position = pos; Normal = norm; Texture = tex; }