Beispiel #1
0
        public object Clone()
        {
            GeometryManager g = new GeometryManager();

            foreach (var x in _vertex)
            {
                Vertex2D v = (Vertex2D)x.Clone();
                g._vertex.Add(v);

                WeightFunc2D w;
                if (weightfunc.TryGetValue(x, out w))
                {
                    g.weightfunc.Add(v, w);
                }
            }

            foreach (var x in _edge)
            {
                g._edge.Add((Edge2D)x.Clone());
            }

            foreach (var x in triangle)
            {
                Triangle2D tr = (Triangle2D)x.Clone();
                g._triangle.Add(tr);

                ElementCutParameters p;
                if (cutParam.TryGetValue(x, out p))
                {
                    g.cutParam.Add(tr, (ElementCutParameters)p.Clone());
                }
            }

            return(g);
        }
Beispiel #2
0
        public GeometryManager(double[,] point, int[,] element)
        {
            _vertex    = new List <Vertex2D>();
            _edge      = new List <Edge2D>();
            _triangle  = new List <Triangle2D>();
            cutParam   = new Dictionary <Triangle2D, ElementCutParameters>();
            weightfunc = new Dictionary <Vertex2D, WeightFunc2D>();

            for (int n = 0; n < point.GetLength(0); n++)
            {
                Vertex2D v = new Vertex2D();
                v.X     = point[n, 0];
                v.Y     = point[n, 1];
                v.extID = n + 1;
                _vertex.Add(v);
            }

            for (int n = 0; n < element.GetLength(0); n++)
            {
                Vertex2D v1 = _vertex.Find(item => item.extID == element[n, 0]);
                Vertex2D v2 = _vertex.Find(item => item.extID == element[n, 1]);
                Vertex2D v3 = _vertex.Find(item => item.extID == element[n, 2]);

                Triangle2D t = new Triangle2D(v1, v2, v3);
                t.extID = n + 1;

                _triangle.Add(t);

                t.E1 = AddEdgeIfNotExist(v1, v2);
                t.E2 = AddEdgeIfNotExist(v2, v3);
                t.E3 = AddEdgeIfNotExist(v3, v1);
            }
        }
Beispiel #3
0
        public double Distance(Vertex2D vert)
        {
            double l = this.Length();

            double dx0 = V2.X - V1.X;
            double dy0 = V2.Y - V1.Y;

            double dx = vert.X - V1.X;
            double dy = vert.Y - V1.Y;

            double p = dx * dx0 + dy * dy0;

            p /= l;

            if (p < 0.0)
            {
                return(Math.Sqrt(dx * dx + dy * dy));
            }

            if (p > l)
            {
                double dx1 = vert.X - V2.X;
                double dy1 = vert.Y - V2.Y;
                return(Math.Sqrt(dx1 * dx1 + dy1 * dy1));
            }

            double L = Math.Sqrt(dx * dx + dy * dy);

            return(Math.Sqrt(L * L - p * p));
        }
Beispiel #4
0
        public override object Clone()
        {
            Vertex2D v1 = (Vertex2D)V1.Clone();
            Vertex2D v2 = (Vertex2D)V2.Clone();

            Edge2D e = new Edge2D(v1, v2);

            e.extID = extID;

            return(e);
        }
Beispiel #5
0
        public override object Clone()
        {
            Vertex2D v = new Vertex2D();

            v.X = X;
            v.Y = Y;

            v.extID = extID;

            return(v);
        }
Beispiel #6
0
        public Vertex2D Verteces2LinCut(double t)
        {
            double x = V1.X + t * (V2.X - V1.X);
            double y = V1.Y + t * (V2.Y - V1.Y);

            Vertex2D v = new Vertex2D();

            v.X = x;
            v.Y = y;

            return(v);
        }
Beispiel #7
0
        public override object Clone()
        {
            Vertex2D v1 = (Vertex2D)V1.Clone();
            Vertex2D v2 = (Vertex2D)V2.Clone();
            Vertex2D v3 = (Vertex2D)V3.Clone();

            Triangle2D tr = new Triangle2D(v1, v2, v3);

            tr.extID = extID;

            tr.E1 = (Edge2D)E1.Clone();
            tr.E2 = (Edge2D)E2.Clone();
            tr.E3 = (Edge2D)E3.Clone();

            return(tr);
        }
Beispiel #8
0
        public double LinearCut(Edge2D e)
        {
            double x0 = e.V1.X;
            double y0 = e.V1.Y;

            double x1 = e.V2.X;
            double y1 = e.V2.Y;

            Func <double, double> Lin = (t) =>
            {
                Vertex2D v = e.Verteces2LinCut(t);
                return(Calc(v.X, v.Y));
            };

            return(Dihotomy(Lin, 0.0, 1.0, 1e-3));
        }
Beispiel #9
0
        private Vertex2D FarestInDirection(double Vx, double Vy)
        {
            double   dist = double.NegativeInfinity;
            double   d    = double.NaN;
            Vertex2D V    = null;

            foreach (var v in _vertex)
            {
                d = Vx * v.X + Vy * v.Y;
                if (d > dist)
                {
                    dist = d;
                    V    = v;
                }
            }
            return(V);
        }
Beispiel #10
0
        private double minDist(List <Edge2D> lst, double X, double Y)
        {
            Vertex2D v = new Vertex2D();

            v.X = X;
            v.Y = Y;

            double d_min = double.PositiveInfinity;

            foreach (var e in lst)
            {
                double d = e.Distance(v);
                if (d < d_min)
                {
                    d_min = d;
                }
            }
            return(d_min);
        }
Beispiel #11
0
        private Edge2D AddEdgeIfNotExist(Vertex2D v1, Vertex2D v2)
        {
            Edge2D e1 = _edge.Find(item => (item.V1.ID == v1.ID) & (item.V2.ID == v2.ID));
            Edge2D e2 = _edge.Find(item => (item.V1.ID == v2.ID) & (item.V2.ID == v1.ID));

            if (e1 != null)
            {
                return(e1);
            }

            if (e2 != null)
            {
                return(e2);
            }

            Edge2D e = new Edge2D(v1, v2);

            _edge.Add(e);
            return(e);
        }
Beispiel #12
0
        public void CutLine(Triangle2D triangle, CurveLine curve, bool CalcAreaRelations)
        {
            double t1 = curve.LinearCut(triangle.E1);
            double t2 = curve.LinearCut(triangle.E2);
            double t3 = curve.LinearCut(triangle.E3);

            if (!double.IsNaN(t1))
            {
                T1 = t1;
            }
            if (!double.IsNaN(t2))
            {
                T2 = t2;
            }
            if (!double.IsNaN(t3))
            {
                T3 = t3;
            }

            if ((T1 > 0.0) & (T2 > 0.0))
            {
                Vertex2D v1 = triangle.E1.Verteces2LinCut(T1);
                Vertex2D v2 = triangle.E2.Verteces2LinCut(T2);
                Cut = new Edge2D(v1, v2);
            }

            if ((T2 > 0.0) & (T3 > 0.0))
            {
                Vertex2D v2 = triangle.E2.Verteces2LinCut(T2);
                Vertex2D v3 = triangle.E3.Verteces2LinCut(T3);
                Cut = new Edge2D(v2, v3);
            }
            if ((T3 > 0.0) & (T1 > 0.0))
            {
                Vertex2D v3 = triangle.E3.Verteces2LinCut(T3);
                Vertex2D v1 = triangle.E1.Verteces2LinCut(T1);
                Cut = new Edge2D(v3, v1);
            }

            if (T1 == 0.0)
            {
                Vertex2D v2 = triangle.E2.Verteces2LinCut(T2);
                Vertex2D v0 = (Vertex2D)triangle.V1.Clone();
                Cut = new Edge2D(v2, v0);
            }
            if (T2 == 0.0)
            {
                Vertex2D v3 = triangle.E3.Verteces2LinCut(T3);
                Vertex2D v0 = (Vertex2D)triangle.V2.Clone();
                Cut = new Edge2D(v3, v0);
            }
            if (T3 == 0.0)
            {
                Vertex2D v1 = triangle.E1.Verteces2LinCut(T1);
                Vertex2D v0 = (Vertex2D)triangle.V3.Clone();
                Cut = new Edge2D(v1, v0);
            }

            if (CalcAreaRelations)
            {
                AreaRelationCalculate(triangle, curve);
            }
        }
Beispiel #13
0
 public Triangle2D(Vertex2D v1, Vertex2D v2, Vertex2D v3)
     : base(v1, v2, v3)
 {
 }
Beispiel #14
0
 public Edge2D(Vertex2D v1, Vertex2D v2) : base(v1, v2)
 {
 }