Example #1
0
        public double Area()
        {
            RHVector3 d1 = vertices[1].pos.Subtract(vertices[0].pos);
            RHVector3 d2 = vertices[2].pos.Subtract(vertices[1].pos);

            return(0.5 * d1.CrossProduct(d2).Length);
        }
Example #2
0
        public void LaplaceRelaxation(TopoModel model)
        {
            double    n      = 2;
            RHVector3 newPos = new RHVector3(pos);

            newPos.AddInternal(pos);
            foreach (TopoTriangle t in connectedFacesList)
            {
                int idx = t.VertexIndexFor(this);
                n += 2;
                newPos.AddInternal(t.vertices[(idx + 1) % 3].pos);
                newPos.AddInternal(t.vertices[(idx + 2) % 3].pos);
            }
            newPos.Scale(1.0 / n);
            // validate newPos does not create intersecting triangles or bad shapes
            foreach (TopoTriangle t in connectedFacesList)
            {
                int       idx    = t.VertexIndexFor(this);
                RHVector3 d1     = t.vertices[(idx + 1) % 3].pos.Subtract(newPos);
                RHVector3 d2     = t.vertices[(idx + 2) % 3].pos.Subtract(t.vertices[(idx + 1) % 3].pos);
                RHVector3 normal = d1.CrossProduct(d2);
                if (normal.ScalarProduct(t.normal) < 0)
                {
                    return;
                }
                double angle = t.AngleEdgePoint((idx + 1) % 3, newPos);
                if (angle < 0.088 || angle > 2.96)
                {
                    return; // Angle gets to small
                }
            }
            model.vertices.ChangeCoordinates(this, newPos);
        }
Example #3
0
        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();
        }
Example #4
0
        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;
            }
        }