public static IVector3D Reverse(IVector3D vec) { IVector3D vector = new IVector3D(vec.X, vec.Y, vec.Z); vector.Reverse(); return(vector); }
public static IVector3D CreateUnitVector(IVector3D toVector, IVector3D fromVector) { IVector3D vector = IVector3D.Sub(toVector, fromVector); vector.Norm(); return(vector); }
public static IVector3D Norm(IVector3D vector) { IVector3D unit = new IVector3D(vector); unit.Norm(); return(unit); }
public static IVector3D Add(IVector3D vector, double value) { vector.X += value; vector.Y += value; vector.Z += value; return(vector); }
public static IVector3D VectorWithMagnitude(IVector3D vector, double magnitude) { IVector3D unit = IVector3D.Norm(vector); unit.Mult(magnitude); return(unit); }
public static IVector3D Rotate2D(IVector3D vector, double angle) { Double x = vector.X * Math.Cos(angle) - vector.Y * Math.Sin(angle); Double y = vector.Y * Math.Sin(angle) + vector.Y * Math.Cos(angle); Double z = vector.Z; IVector3D rVector = new IVector3D(x, y, z); return(rVector); }
public static IVector3D operator /(IVector3D vector, double scalar) { IVector3D newVector = new IVector3D(); if (scalar != 0) { newVector = new IVector3D(vector.X / scalar, vector.Y / scalar, vector.Z / scalar); } return(newVector); }
public static IVector3D operator *(IVector3D vector1, IVector3D vector2) { IVector3D crossVector; double Cx = vector1.Y * vector2.Z - vector1.Z * vector2.Y; double Cy = vector1.Z * vector2.X - vector1.X * vector2.Z; double Cz = vector1.X * vector2.Y - vector1.Y * vector2.X; crossVector = new IVector3D(Cx, Cy, Cz); return(crossVector); }
public static IVector3D operator *(IVector3D vector, ITopologicVertex vertex) { IVector3D crossVector; double Cx = vector.Y * vertex.Z - vector.Z * vertex.Y; double Cy = vector.Z * vertex.X - vector.X * vertex.Z; double Cz = vector.X * vertex.Y - vector.Y * vertex.X; crossVector = new IVector3D(Cx, Cy, Cz); return(crossVector); }
public void Cross(IVector3D vector) { double Cx = X * vector.Z - X * vector.Y; double Cy = Y * vector.X - Y * vector.Z; double Cz = Z * vector.Y - Z * vector.X; X = Cx; Y = Cy; Z = Cz; }
internal IPoint3D ComputeAveragePosition(int[] keys) { IVector3D v = new IVector3D(); for (int i = 0; i < keys.Length; i++) { v += iM.GetVertexWithKey(keys[i]).Position; } v /= keys.Length; return(new IPoint3D(v.X, v.Y, v.Z)); }
public IVector3D GetHalfFacetCenter(int[] hf) { IVector3D center = new IVector3D(); foreach (int eV in hf) { center += iM.GetVertexWithKey(eV).Position; } center /= hf.Length; return(center); }
public static IVector3D MassiveAddition(IVector3D[] vectorsToAdd) { IVector3D newVector = new IVector3D(); foreach (IVector3D v in vectorsToAdd) { newVector.X += v.X; newVector.Y += v.Y; newVector.Z += v.Z; } return(newVector); }
public static Double AngleBetween(IVector3D vector1, IVector3D vector2) { Double dot = IVector3D.Dot(vector1, vector2); Double m1 = Math.Sqrt((vector1.X * vector1.X) + (vector1.Y * vector1.Y) + (vector1.Z * vector1.Z)); Double m2 = Math.Sqrt((vector2.X * vector2.X) + (vector2.Y * vector2.Y) + (vector2.Z * vector2.Z)); Double angle = Math.Acos(dot / (m1 * m2)); if (Double.IsNaN(angle)) { angle = (double)0; } return(angle); }
public IVector3D ComputeVertexNormal(int vKey) { int[] eKeys = GetVertexIncidentElements(vKey); IVector3D normal = new IVector3D(); IVector3D n, p; foreach (int eK in eKeys) { ComputeTwoDimensionalElementNormal(eK, out n, out p); normal += n; } normal.Norm(); return(normal); }
public IMatrix TensorProduct(IVector3D vec) { double[][] data = new double[3][]; data[0] = new double[3] { X *vec.X, X *vec.Y, X *vec.Z }; data[1] = new double[3] { Y *vec.X, Y *vec.Y, Y *vec.Z }; data[2] = new double[3] { Z *vec.X, Z *vec.Y, Z *vec.Z }; return(new IMatrix(data)); }
public static double AngleBetween(IPoint3D pt1, IPoint3D pt2, IPoint3D origin) { IVector3D v1 = IVector3D.CreateVector(pt1, origin); IVector3D v2 = IVector3D.CreateVector(pt2, origin); double dot = IVector3D.Dot(v1, v2); double cos = dot / (v1.Mag() * v2.Mag()); double angle = Math.Acos(cos); if (Double.IsNaN(angle)) { angle = (double)0; } return(angle); }
public static IVector3D Cross(IVector3D vector1, IVector3D vector2, Boolean unitize) { IVector3D crossVector; double Cx = vector1.Y * vector2.Z - vector1.Z * vector2.Y; double Cy = vector1.Z * vector2.X - vector1.X * vector2.Z; double Cz = vector1.X * vector2.Y - vector1.Y * vector2.X; crossVector = new IVector3D(Cx, Cy, Cz); if (unitize) { crossVector.Norm(); } return(crossVector); }
public void ComputeEdgeNormals(out IVector3D[] normals, out IVector3D[] centers, out ITopologicEdge[] edges) { Int64[] eKeys = iM.Topology.GetUniqueEdges(); edges = new ITopologicEdge[eKeys.Length]; normals = new IVector3D[eKeys.Length]; centers = new IVector3D[eKeys.Length]; int start, end; for (int i = 0; i < eKeys.Length; i++) { Int64 eK = eKeys[i]; IHelpers.UnpackKey(eK, out start, out end); edges[i] = new ITopologicEdge(iM.GetVertexWithKey(start), iM.GetVertexWithKey(end)); iM.Topology.ComputeEdgeNormal(start, end, out normals[i], out centers[i]); } }
public IVector3D ComputeVertexNormalAsFaceAreaWeighted(int vKey) { int[] eKeys = GetVertexIncidentElements(vKey); IVector3D normal = new IVector3D(); IVector3D n, p; double area; foreach (int eK in eKeys) { ComputeTwoDimensionalElementNormal(eK, out n, out p); area = ComputeTwoDimensionalElementArea(eK); n *= area; normal += n; } normal.Norm(); return(normal); }
public override Boolean Equals(Object obj) { Boolean equal = false; try { IVector3D vector = (IVector3D)obj; if (X == vector.X && Y == vector.Y && Z == vector.Z) { equal = true; } else { equal = false; } } catch (Exception) { } return(equal); }
public bool ComputePolygonNormal(IPoint3D[] polygon, out IVector3D normal, out IVector3D position) { normal = new IVector3D(); position = new IVector3D(); if (polygon.Length > 2) { IVector3D v1, v2; IVector3D vv0 = new IVector3D(); IVector3D vv1 = new IVector3D(); IVector3D vv2 = new IVector3D(); int prev_i, next_i; for (int i = 0; i < polygon.Length; i++) { prev_i = i - 1; if (i == 0) { prev_i = polygon.Length - 1; } next_i = i + 1; if (i == polygon.Length - 1) { next_i = 0; } vv0 += polygon[i]; vv1 += polygon[prev_i]; vv2 += polygon[next_i]; v1 = vv1 - vv0; v2 = vv2 - vv0; normal += v1 * v2; position += vv0; } normal /= polygon.Length; position /= polygon.Length; normal.Norm(); return(true); } return(false); }
public bool ComputeTwoDimensionalElementNormal(int eKey, out IVector3D normal, out IVector3D position) { IElement e = iM.GetElementWithKey(eKey); normal = new IVector3D(); position = new IVector3D(); if (e.TopologicDimension == 2) { IVector3D v1, v2; ITopologicVertex vv0, vv1, vv2; int prev_i, next_i; for (int i = 0; i < e.VerticesCount; i++) { prev_i = i - 1; if (i == 0) { prev_i = e.VerticesCount - 1; } next_i = i + 1; if (i == e.VerticesCount - 1) { next_i = 0; } vv0 = iM.GetVertexWithKey(e.Vertices[i]); vv1 = iM.GetVertexWithKey(e.Vertices[prev_i]); vv2 = iM.GetVertexWithKey(e.Vertices[next_i]); v1 = vv1.Position - vv0.Position; v2 = vv2.Position - vv0.Position; normal += v1 * v2; position += vv0.Position; } normal /= e.VerticesCount; position /= e.VerticesCount; normal.Norm(); return(true); } return(false); }
public int[] GetVertexIncidentElementsSorted(int vertexKey) { int[] nKeys = iM.Topology.GetVertexIncidentElements(vertexKey); if (nKeys.Length > 1) { IPoint3D[] refPt = new IPoint3D[2]; refPt[0] = ComputeAveragePosition(iM.GetElementWithKey(nKeys[0]).Vertices); refPt[1] = ComputeAveragePosition(iM.GetElementWithKey(nKeys[1]).Vertices); IVector3D refVec = refPt[1] - refPt[0]; List <int> results = nKeys.Skip(1).OrderBy(nK => IVector3D.AngleBetween(refVec, ComputeAveragePosition(iM.GetElementWithKey(nK).Vertices) - refPt[0]) ).ToList(); results.Insert(0, nKeys[0]); nKeys = results.ToArray(); } return(nKeys); }
public int[] GetVertexAdjacentVerticesSorted(int vertexKey) { int[] nKeys = iM.Topology.GetVertexAdjacentVertices(vertexKey); if (nKeys.Length > 1) { IPoint3D[] refPt = new IPoint3D[2]; refPt[0] = iM.GetVertexWithKey(nKeys[0]).Position; refPt[1] = iM.GetVertexWithKey(nKeys[1]).Position; IVector3D refVec = refPt[1] - refPt[0]; List <int> results = nKeys.Skip(1).OrderBy(nK => IVector3D.AngleBetween(refVec, iM.GetVertexWithKey(nK).Position - refPt[0]) ).ToList(); results.Insert(0, nKeys[0]); nKeys = results.ToArray(); } return(nKeys); }
public bool ComputeTwoDimensionalHalfFacetNormal(int[] hf, out IVector3D normal, out IVector3D position) { normal = new IVector3D(); position = new IVector3D(); if (hf.Length > 2) { IVector3D v1, v2; ITopologicVertex vv0, vv1, vv2; int prev_i, next_i; for (int i = 0; i < hf.Length; i++) { prev_i = i - 1; if (i == 0) { prev_i = hf.Length - 1; } next_i = i + 1; if (i == hf.Length - 1) { next_i = 0; } vv0 = iM.GetVertexWithKey(hf[i]); vv1 = iM.GetVertexWithKey(hf[prev_i]); vv2 = iM.GetVertexWithKey(hf[next_i]); v1 = vv1.Position - vv0.Position; v2 = vv2.Position - vv0.Position; normal += v1 * v2; position += vv0.Position; } normal /= hf.Length; position /= hf.Length; normal.Norm(); return(true); } return(false); }
/// <summary> /// Return the cosine dihedral angles among pairs of two-dimensional elements incident to the given edge. /// More than one dihedral angle can be returned since the data structure supports non-manifold meshes. /// </summary> /// <param name="vKey1"></param> /// <param name="vKey2"></param> /// <returns></returns> public double[] ComputeEdgeCosDihedralAngle(int vKey1, int vKey2) { int[] eKey = GetEdgeIncidentElements(vKey1, vKey2); double[] dA = new double[0]; if (eKey.Length > 1) { IVector3D n1, n2, p1, p2; double d; int count = eKey.Length - 1; int next_i; if (eKey.Length > 2) { count = eKey.Length; } dA = new double[count]; for (int i = 0; i < count; i++) { next_i = i + 1; if (i == eKey.Length - 1) { next_i = 0; } ComputeTwoDimensionalElementNormal(eKey[i], out n1, out p1); ComputeTwoDimensionalElementNormal(eKey[next_i], out n2, out p2); d = IVector3D.Dot(n1, n2); if (d > 1) { d = 1; } else if (d < -1) { d = -1; } dA[i] = d; } } return(dA); }
public bool ComputeEdgeNormal(int vKey1, int vKey2, out IVector3D normal, out IVector3D center) { int[] eKeys = GetEdgeIncidentElements(vKey1, vKey2); normal = new IVector3D(); center = iM.GetVertexWithKey(vKey1).Position + iM.GetVertexWithKey(vKey2).Position; center /= 2; if (eKeys.Length == 0) { return(false); } foreach (int eK in eKeys) { IVector3D n, p; ComputeTwoDimensionalElementNormal(eK, out n, out p); normal += n; } normal /= eKeys.Length; normal.Norm(); return(true); }
public IVector3D(IVector3D vector) { this.X = vector.X; this.Y = vector.Y; this.Z = vector.Z; }
public static IVector3D CreateVector(IVector3D toVector, IVector3D fromVector) { return(IVector3D.Sub(toVector, fromVector)); }