Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public TopoTriangle(TopoModel model, TopoVertex v1, TopoVertex v2, TopoVertex v3, double nx, double ny, double nz)
        {
            vertices[0] = v1;
            vertices[1] = v2;
            vertices[2] = v3;
            RHVector3 normalTest = new RHVector3(nx, ny, nz);

            //normal.NormalizeSafe();
            edges[0] = model.getOrCreateEdgeBetween(v1, v2);
            edges[1] = model.getOrCreateEdgeBetween(v2, v3);
            edges[2] = model.getOrCreateEdgeBetween(v3, v1);
            edges[0].connectFace(this);
            edges[1].connectFace(this);
            edges[2].connectFace(this);
            v1.connectFace(this);
            v2.connectFace(this);
            v3.connectFace(this);
            boundingBox.Add(v1.pos);
            boundingBox.Add(v2.pos);
            boundingBox.Add(v3.pos);
            RecomputeNormal();
            if (normalTest.ScalarProduct(normal) < 0)
            {
                FlipDirection();
            }

            /* double d1 = edges[0].EdgeLength;
             * double d2 = edges[1].EdgeLength;
             * double d3 = edges[2].EdgeLength;
             * if (d1 < epsilonZero || d2 < epsilonZero || d3 < epsilonZero)
             *   Console.WriteLine("Df:" + this);*/
        }
Ejemplo n.º 3
0
        public bool ProjectPoint(RHVector3 p, out double lambda, RHVector3 pProjected)
        {
            RHVector3 u = v2.pos.Subtract(v1.pos);

            lambda       = p.Subtract(v1.pos).ScalarProduct(u) / u.ScalarProduct(u);
            pProjected.x = v1.pos.x + lambda * u.x;
            pProjected.y = v1.pos.y + lambda * u.y;
            pProjected.z = v1.pos.z + lambda * u.z;
            return(lambda >= 0 && lambda <= 1);
        }
Ejemplo n.º 4
0
        public double DistanceToPlane(RHVector3 pos)
        {
            double d = vertices[0].pos.ScalarProduct(normal);

            return(pos.ScalarProduct(normal) - d);
        }
Ejemplo n.º 5
0
 public TopoPlane(RHVector3 _normal, RHVector3 pointOnPlane)
 {
     normal = new RHVector3(_normal);
     normal.NormalizeSafe();
     d = pointOnPlane.ScalarProduct(normal);
 }
Ejemplo n.º 6
0
 public TopoPlane(RHVector3 _normal, RHVector3 pointOnPlane)
 {
     normal = new RHVector3(_normal);
     normal.NormalizeSafe();
     d = pointOnPlane.ScalarProduct(normal);
 }