예제 #1
0
        // Return the center of the polygon provided, usually BasicVertices or ValueVertices
        public CoordPoint CenterOfPolygon(List <CoordPoint> Vertices)
        {
            CoordPoint result = new CoordPoint();

            foreach (CoordPoint p in Vertices)
            {
                result.X += p.X;
                result.Y += p.Y;
            }

            result.X /= Vertices.Count;
            result.Y /= Vertices.Count;

            return(result);
        }
예제 #2
0
        // Return the center of the polygon provided, usually BasicVertices or ValueVertices
        public CoordPoint CenterOfPolygon(List<CoordPoint> Vertices)
        {
            CoordPoint result = new CoordPoint();

            foreach (CoordPoint p in Vertices)
            {
                result.X += p.X;
                result.Y += p.Y;
            }

            result.X /= Vertices.Count;
            result.Y /= Vertices.Count;

            return result;
        }
예제 #3
0
        // Called when the FuzzyVariable it belongs to gets updated. Updates ValueVertices accordingly
        public void SetMembershipForX(double x)
        {
            //Console.WriteLine(Name + " " + x);
            // If x falls in the set's range, go through the set's points, find the one it lies between, and insert 
            if (x >= Lower_Bound && x <= Upper_Bound)
            {
                List<CoordPoint> newValueVertices = new List<CoordPoint>();
                CoordPoint newPoint1 = new CoordPoint();
                double y = 0;


                for (int i = 0; i < BaseVertices.Count - 1; i++ )
                {
                    CoordPoint p1 = BaseVertices[i];
                    CoordPoint p2 = BaseVertices[i + 1];

                    if (x >= p1.X && x <= p2.X)
                    {
                        y = p1.Y + ((x - p1.X) / (p2.X - p1.X)) * (p2.Y - p1.Y);
                        break;
                    }
                }
                
                // Insert a point in between all points where y is between P1 & P2.Y
                
                
                for (int i = 0; i < BaseVertices.Count - 1; i++ )
                {
                    CoordPoint p1 = BaseVertices[i];
                    CoordPoint p2 = BaseVertices[i + 1];
                    //Console.WriteLine("   (" + p1.X + ", " + p1.Y + "), (" + p2.X + ", " + p2.Y + ")");

                    //newValueVertices.Add(BaseVertices[i]);
                    if ((y >= p1.Y && y < p2.Y && p1.Y < p2.Y) || (y <= p1.Y && y >= p2.Y && p1.Y > p2.Y))
                    {
                        // Upslope: add p1 but not p2
                        // downslope: add p2 but not p1
                        if (p1.Y < p2.Y)
                            newValueVertices.Add(BaseVertices[i]);

                        newPoint1.X = p1.X + ((y - p1.Y) / (p2.Y - p1.Y)) * (p2.X - p1.X);
                        newPoint1.Y = y;
                        //Console.WriteLine("       (" + newPoint1.X + ", " + newPoint1.Y + ")");
                        newValueVertices.Add(newPoint1.Clone());

                        if (p1.Y > p2.Y)
                            newValueVertices.Add(BaseVertices[i + 1]);
                    }
                    else 
                    { 
                        newValueVertices.Add(BaseVertices[i]); 
                    }
                }

                _valueVertices = newValueVertices;

                _membershipValue = newPoint1.Y;

            }
            else
            {
                _membershipValue = 0;
                _valueVertices = new List<CoordPoint>();
            }
            
        }
예제 #4
0
        // Called when the FuzzyVariable it belongs to gets updated. Updates ValueVertices accordingly
        public void SetMembershipForX(double x)
        {
            //Console.WriteLine(Name + " " + x);
            // If x falls in the set's range, go through the set's points, find the one it lies between, and insert
            if (x >= Lower_Bound && x <= Upper_Bound)
            {
                List <CoordPoint> newValueVertices = new List <CoordPoint>();
                CoordPoint        newPoint1        = new CoordPoint();
                double            y = 0;


                for (int i = 0; i < BaseVertices.Count - 1; i++)
                {
                    CoordPoint p1 = BaseVertices[i];
                    CoordPoint p2 = BaseVertices[i + 1];

                    if (x >= p1.X && x <= p2.X)
                    {
                        y = p1.Y + ((x - p1.X) / (p2.X - p1.X)) * (p2.Y - p1.Y);
                        break;
                    }
                }

                // Insert a point in between all points where y is between P1 & P2.Y


                for (int i = 0; i < BaseVertices.Count - 1; i++)
                {
                    CoordPoint p1 = BaseVertices[i];
                    CoordPoint p2 = BaseVertices[i + 1];
                    //Console.WriteLine("   (" + p1.X + ", " + p1.Y + "), (" + p2.X + ", " + p2.Y + ")");

                    //newValueVertices.Add(BaseVertices[i]);
                    if ((y >= p1.Y && y < p2.Y && p1.Y < p2.Y) || (y <= p1.Y && y >= p2.Y && p1.Y > p2.Y))
                    {
                        // Upslope: add p1 but not p2
                        // downslope: add p2 but not p1
                        if (p1.Y < p2.Y)
                        {
                            newValueVertices.Add(BaseVertices[i]);
                        }

                        newPoint1.X = p1.X + ((y - p1.Y) / (p2.Y - p1.Y)) * (p2.X - p1.X);
                        newPoint1.Y = y;
                        //Console.WriteLine("       (" + newPoint1.X + ", " + newPoint1.Y + ")");
                        newValueVertices.Add(newPoint1.Clone());

                        if (p1.Y > p2.Y)
                        {
                            newValueVertices.Add(BaseVertices[i + 1]);
                        }
                    }
                    else
                    {
                        newValueVertices.Add(BaseVertices[i]);
                    }
                }

                _valueVertices = newValueVertices;

                _membershipValue = newPoint1.Y;
            }
            else
            {
                _membershipValue = 0;
                _valueVertices   = new List <CoordPoint>();
            }
        }