public void RecomputeNormal() { RHVector3 d1 = vertices[1].pos.Subtract(vertices[0].pos); RHVector3 d2 = vertices[2].pos.Subtract(vertices[1].pos); normal = d1.CrossProduct(d2); normal.NormalizeSafe(); }
public double alphaBeta; // Sum of dihedral angles to a virtual shared triangle public TopoEdgePair(TopoEdge _edgeA, TopoEdge _edgeB) { edgeA = _edgeA; edgeB = _edgeB; RHVector3 sharedPoint = null; RHVector3 p1 = null, p2 = null; if (edgeA.v1 == edgeB.v1) { sharedPoint = edgeA.v1.pos; p1 = edgeA.v2.pos; p2 = edgeB.v2.pos; } else if (edgeA.v1 == edgeB.v2) { sharedPoint = edgeA.v1.pos; p1 = edgeA.v2.pos; p2 = edgeB.v1.pos; } else if (edgeA.v2 == edgeB.v1) { sharedPoint = edgeA.v1.pos; p1 = edgeA.v1.pos; p2 = edgeB.v2.pos; } else if (edgeA.v2 == edgeB.v2) { sharedPoint = edgeA.v2.pos; p1 = edgeA.v1.pos; p2 = edgeB.v1.pos; } RHVector3 d1 = p1.Subtract(sharedPoint); RHVector3 d2 = p2.Subtract(sharedPoint); RHVector3 normal = d1.CrossProduct(d2); normal.NormalizeSafe(); alphaBeta = normal.AngleForNormalizedVectors(edgeA.faces.First.Value.normal) + normal.AngleForNormalizedVectors(edgeB.faces.First.Value.normal); if (alphaBeta > Math.PI) // normal was wrong direction { alphaBeta = 2 * Math.PI - alphaBeta; } }
public void importSTL(string filename) { StartAction("L_LOADING..."); clear(); try { FileStream f = File.OpenRead(filename); byte[] header = new byte[80]; ReadArray(f, header); /* if (header[0] == 's' && header[1] == 'o' && header[2] == 'l' && header[3] == 'i' && header[4] == 'd') { f.Close(); LoadText(file); } else {*/ BinaryReader r = new BinaryReader(f); int nTri = r.ReadInt32(); if (f.Length != 84 + nTri * 50) { f.Close(); importSTLAscii(filename); } else { for (int i = 0; i < nTri; i++) { Progress((double)i / nTri); if (i % 2000 == 0) { Application.DoEvents(); if(IsActionStopped()) return; } RHVector3 normal = new RHVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); RHVector3 p1 = new RHVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); RHVector3 p2 = new RHVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); RHVector3 p3 = new RHVector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); normal.NormalizeSafe(); addTriangle(p1, p2, p3, normal); r.ReadUInt16(); } r.Close(); f.Close(); } } catch (Exception e) { MessageBox.Show(e.ToString(), "Error reading STL file", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public TopoPlane(RHVector3 _normal, RHVector3 pointOnPlane) { normal = new RHVector3(_normal); normal.NormalizeSafe(); d = pointOnPlane.ScalarProduct(normal); }
public TopoPlane(RHVector3 _normal, RHVector3 pointOnPlane) { normal = new RHVector3(_normal); normal.NormalizeSafe(); d = pointOnPlane.ScalarProduct(normal); }