/// <summary> /// Multiplies matrix with a V4f. /// </summary> public static V4f Multiply(M22f mat, V4f vec) { return(new V4f(mat.M00 * vec.X + mat.M01 * vec.Y, mat.M10 * vec.X + mat.M11 * vec.Y, vec.Z, vec.W)); }
/// <summary> /// Multiplacation of a <see cref="Scale3f"/> with a <see cref="V4f"/>. /// </summary> public static V4f Multiply(Scale3f scale, V4f vec) { return(new V4f(scale.X * vec.X, scale.Y * vec.Y, scale.Z * vec.Z, vec.W)); }
public static V4f Transform(this Rot2f rot, V4f v) { float a = Fun.Cos(rot.Angle); float b = Fun.Sin(rot.Angle); return(new V4f(a * v.X + -b * v.Y, b * v.X + a * v.Y, v.Z, v.W)); }
/// <summary> /// Calculates the centroid for a given set of V4fs. /// </summary> public static V4f ComputeCentroid(this V4f[] vectors) { V4f sum = V4f.Zero; for (var i = 0; i < vectors.Length; i++) { sum += vectors[i]; } return(sum / (float)vectors.Length); }
/// <summary> /// Calculates the centroid for a given set of V4fs. /// </summary> public static V4f ComputeCentroid(this V4f[] vectors, int[] indices) { V4f sum = V4f.Zero; for (var i = 0; i < indices.Length; i++) { sum += vectors[indices[i]]; } return(sum / (float)indices.Length); }
/// <summary> /// Calculates the sum for a given set of V4fs. /// </summary> public static V4f Sum(this IEnumerable <V4f> vectors) { V4f sum = V4f.Zero; foreach (var e in vectors) { sum += e; } return(sum); }
/// <summary> /// Calculates the sum for a given set of V4fs. /// </summary> public static V4f Sum(this V4f[] vectors) { V4f sum = V4f.Zero; for (var i = 0; i < vectors.Length; i++) { sum += vectors[i]; } return(sum); }
/// <summary> /// Calculates a weighted centroid for a given array of V4fs. /// </summary> public static V4f ComputeCentroid(this V4f[] vectors, float[] weights) { V4f sum = V4f.Zero; float weightSum = 0; for (int i = 0; i < vectors.Length; i++) { sum += weights[i] * vectors[i]; weightSum += weights[i]; } return(sum / weightSum); }
/// <summary> /// Calculates the centroid for a given set of V4fs. /// </summary> public static V4f ComputeCentroid(this IEnumerable <V4f> vectors) { V4f sum = V4f.Zero; int count = 0; foreach (var e in vectors) { sum += e; count++; } return(sum / (float)count); }
/// <summary> /// Calculates a weighted centroid for vectors and weights given by indices. /// Sum(vectors[indices[i]] * weights[indices[i]]) / Sum(weights[indices[i]]. /// </summary> public static V4f ComputeCentroid(this V4f[] vectors, float[] weights, int[] indices) { V4f sum = V4f.Zero; float weightSum = 0; for (int i = 0; i < indices.Length; i++) { var w = weights[indices[i]]; sum += w * vectors[indices[i]]; weightSum += w; } return(sum / weightSum); }
public static V4f Multiply(Rot2f rot, V4f vec) { float a = (float)System.Math.Cos(rot.Angle); float b = (float)System.Math.Sin(rot.Angle); return(new V4f(a * vec.X + b * vec.Y, -b * vec.X + a * vec.Y, vec.Z, vec.W)); }
public static V4f InvTransform(this Rot2f rot, V4f v) => Transform(rot.Inverse, v);
public void Write(V4f x) { Write(x.X); Write(x.Y); Write(x.Z); Write(x.W); }
public QuaternionF(V4f v) { W = v.X; X = v.Y; Y = v.Z; Z = v.W; }
/// <summary>Computes MD5 hash of given data.</summary> public static Guid ComputeMd5Hash(this V4f x) => ComputeMd5Hash(bw => { bw.Write(x.X); bw.Write(x.Y); bw.Write(x.Z); bw.Write(x.W); });