Пример #1
0
        public List <List <Point> > GetFieldlines(List <Triangle> triangles, List <Point> points, double maxX, double maxY, double fiMax, double coef)
        {
            List <List <Point> > fieldlines = new List <List <Point> >();
            var boundaryPoints = triangles.Where(tri => tri.SignBoundaryPointsCount > 0).Select(tri => tri.Circumcenter).ToList();
            var usedTriangles  = new List <Triangle>();
            int i = 0;

            foreach (var point in boundaryPoints)
            {
                Triangle   t2d = new Triangle(new Point(0, 10), new Point(10, 20), point);
                Triangle3D t3d = new Triangle3D(new Point3D(), new Point3D(), new Point3D());
                var        p1  = new Point3D(t2d.Vertices[0].X, t2d.Vertices[0].Y, t2d.Vertices[0].Fi);
                var        p2  = new Point3D(t2d.Vertices[1].X, t2d.Vertices[1].Y, t2d.Vertices[1].Fi);
                var        p3  = new Point3D(t2d.Vertices[2].X, t2d.Vertices[2].Y, t2d.Vertices[2].Fi);
                fieldlines.Add(new List <Point>());
                foreach (var triangle in triangles)
                {
                    if (!point.PointInTriangle(point, triangle.Vertices[0], triangle.Vertices[1], triangle.Vertices[2]))
                    {
                        continue;
                    }
                    t2d = triangle;
                    usedTriangles.Add(t2d);
                    p1 = new Point3D(t2d.Vertices[0].X, t2d.Vertices[0].Y, t2d.Vertices[0].Fi);
                    p2 = new Point3D(t2d.Vertices[1].X, t2d.Vertices[1].Y, t2d.Vertices[1].Fi);
                    p3 = new Point3D(t2d.Vertices[2].X, t2d.Vertices[2].Y, t2d.Vertices[2].Fi);

                    t3d = new Triangle3D(p1, p2, p3);
                    break;
                }

                bool intr  = true;
                var  curX  = point.X;
                var  curY  = point.Y;
                var  curFi = -(t3d.A * curX + t3d.B * curY + t3d.D) / t3d.C;
                while (curX <= maxX / 2 && curX >= -maxX / 2 && curY <= maxY / 2 && curY >= -maxY / 2 && Math.Abs(curFi) <= fiMax * 1.5)
                {
                    var addPoint = new Point(curX, curY, curFi);
                    fieldlines[i].Add(addPoint);
                    if (!intr)
                    {
                        break;
                    }
                    if (addPoint.PointInTriangle(addPoint, t2d.Vertices[0], t2d.Vertices[1], t2d.Vertices[2]))
                    {
                        Vector3D v1 = p2 - p1;
                        Vector3D v2 = p3 - p2;

                        // Get the cross product.
                        Vector3D n = Vector3D.CrossProduct(v1, v2);
                        n.Normalize();
                        if (curFi < 0)
                        {
                            n.X = -n.X;
                            n.Y = -n.Y;
                            n.Z = -n.Z;
                        }

                        curX  += coef * n.X;
                        curY  += coef * n.Y;
                        curFi += coef * n.Z;

                        //if (t3d.A * t3d.D < 0)
                        //    curX += coef * Math.Abs(t3d.A);
                        //else
                        //    curX -= coef * Math.Abs(t3d.A);
                        //if (t3d.B * t3d.D < 0)
                        //    curY += coef * Math.Abs(t3d.B);
                        //else
                        //    curY -= coef * Math.Abs(t3d.B);
                        //if (t3d.D > 0)
                        //    curFi -= coef * Math.Abs(t3d.C);
                        //else
                        //    curFi += coef * Math.Abs(t3d.C);

                        //if(coef * Math.Abs(t3d.C) < 0.00001)
                        //    break;
                    }
                    else
                    {
                        intr = false;
                        foreach (var triangle in triangles)
                        {
                            if (addPoint.PointInTriangle(addPoint, triangle.Vertices[0], triangle.Vertices[1], triangle.Vertices[2]))
                            {
                                t2d  = triangle;
                                p1   = new Point3D(t2d.Vertices[0].X, t2d.Vertices[0].Y, t2d.Vertices[0].Fi);
                                p2   = new Point3D(t2d.Vertices[1].X, t2d.Vertices[1].Y, t2d.Vertices[1].Fi);
                                p3   = new Point3D(t2d.Vertices[2].X, t2d.Vertices[2].Y, t2d.Vertices[2].Fi);
                                t3d  = new Triangle3D(p1, p2, p3);
                                intr = true;
                                break;
                            }
                        }
                    }
                }

                ++i;
            }

            return(fieldlines);
        }
Пример #2
0
        public void GetAB(List <Point> points, out List <List <double> > aList, out List <double> bList, double plus, double minus)
        {
            aList = new List <List <double> >();
            bList = new List <double>();
            var i = 0;

            foreach (var iPoint in points)
            {
                var b = double.Epsilon;
                //var b =0.0d;
                aList.Add(new List <double>());
                foreach (var jPoint in points)
                {
                    var a = double.Epsilon;
                    //var a = 0.0d;
                    if (!iPoint.IsBoundary && jPoint.IsBoundary)
                    {
                        var commonTriangles = GetCommonTriangles(iPoint, jPoint).ToList();
                        //var borderTriangle = commonTriangles.Aggregate((i1, i2) => i1.BoundaryPointsCount > i2.BoundaryPointsCount ? i1 : i2);
                        //var innerTriangle = commonTriangles.Aggregate((i1, i2) => i1.BoundaryPointsCount < i2.BoundaryPointsCount ? i1 : i2);
                        if (commonTriangles.Count > 1)
                        {
                            var        lowerVertex1 = commonTriangles[0].Vertices.Where(coord => coord != iPoint && coord != jPoint).ToList().LastOrDefault();
                            var        lowerVertex2 = commonTriangles[1].Vertices.Where(coord => coord != iPoint && coord != jPoint).ToList().LastOrDefault();
                            var        lowV1        = new Point3D(lowerVertex1.X, lowerVertex1.Y, 0);
                            var        lowV2        = new Point3D(lowerVertex2.X, lowerVertex2.Y, 0);
                            var        in0          = new Point3D(jPoint.X, jPoint.Y, 0);
                            var        in1          = new Point3D(jPoint.X, jPoint.Y, 1);
                            var        bor1         = new Point3D(iPoint.X, iPoint.Y, 1);
                            var        bor0         = new Point3D(iPoint.X, iPoint.Y, 0);
                            Triangle3D t11          = new Triangle3D(bor1, lowV1, in0);
                            Triangle3D t12          = new Triangle3D(bor0, lowV1, in1);
                            Triangle3D t21          = new Triangle3D(bor1, lowV2, in0);
                            Triangle3D t22          = new Triangle3D(bor0, lowV2, in1);
                            double     c;
                            if (jPoint.IsInnerBoundaryPlus)
                            {
                                c = plus;
                            }
                            else if (jPoint.IsInnerBoundaryMinus)
                            {
                                c = minus;
                            }
                            else
                            {
                                c = double.Epsilon;
                            }


                            b += c * ((t11.A * t12.A + t11.B * t12.B) * t11.S0 + (t21.A * t22.A + t21.B * t22.B) * t21.S0);
                        }
                    }
                    else if (!iPoint.IsBoundary && iPoint == jPoint)
                    {
                        var triangles = iPoint.AdjacentTriangles.ToList();
                        foreach (var triangle in triangles)
                        {
                            var        lowerVertex = triangle.Vertices.Where(coord => coord != iPoint).ToArray();
                            var        m1          = new Point3D(lowerVertex[0].X, lowerVertex[0].Y, 0);
                            var        m2          = new Point3D(lowerVertex[1].X, lowerVertex[1].Y, 0);
                            var        m3          = new Point3D(iPoint.X, iPoint.Y, 1);
                            Triangle3D t3D         = new Triangle3D(m1, m2, m3);
                            a -= (t3D.A * t3D.A + t3D.B * t3D.B) * t3D.S0;
                        }
                    }
                    else if (GetCommonTriangles(iPoint, jPoint).ToList().Count > 0 && !iPoint.IsBoundary && !jPoint.IsBoundary)
                    {
                        var commonTriangles = GetCommonTriangles(iPoint, jPoint).ToList();
                        if (commonTriangles.Count > 1)
                        {
                            var        lowerVertex1 = commonTriangles[0].Vertices.Where(coord => coord != iPoint && coord != jPoint).ToList().LastOrDefault();
                            var        lowerVertex2 = commonTriangles[1].Vertices.Where(coord => coord != iPoint && coord != jPoint).ToList().LastOrDefault();
                            var        lowV1        = new Point3D(lowerVertex1.X, lowerVertex1.Y, 0);
                            var        lowV2        = new Point3D(lowerVertex2.X, lowerVertex2.Y, 0);
                            var        in0          = new Point3D(jPoint.X, jPoint.Y, 0);
                            var        in1          = new Point3D(jPoint.X, jPoint.Y, 1);
                            var        bor1         = new Point3D(iPoint.X, iPoint.Y, 1);
                            var        bor0         = new Point3D(iPoint.X, iPoint.Y, 0);
                            Triangle3D t11          = new Triangle3D(bor1, lowV1, in0);
                            Triangle3D t12          = new Triangle3D(bor0, lowV1, in1);
                            Triangle3D t21          = new Triangle3D(bor1, lowV2, in0);
                            Triangle3D t22          = new Triangle3D(bor0, lowV2, in1);
                            a -= (t11.A * t12.A + t11.B * t12.B) * t11.S0 + (t21.A * t22.A + t21.B * t22.B) * t21.S0;
                        }
                    }

                    aList[i].Add(a);
                }
                ++i;
                bList.Add(b);
            }
        }