Beispiel #1
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            float oldX = this.Center.X;
            float oldY = this.Center.Y;

            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, oldX, oldY))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, oldX, oldY);
            }

            this.systemCenter = new GlPointR2(x, y);
            updatePointsPosition();

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, oldX, oldY);
            }
        }
Beispiel #2
0
        protected override void updatePointsPosition()
        {
            this.b = -2 * this.a * this.systemCenter.X;
            this.c = this.a * this.a * this.systemCenter.X + this.systemCenter.Y;

            this.COS = directVector.deltaX / directVector.Length;
            this.SIN = directVector.deltaY / directVector.Length;

            float yFocus = 1 / Math.Abs(4 * a);

            this.parabolaFocus = new GlPointR2(-yFocus * SIN + systemCenter.X, yFocus * COS + systemCenter.Y);

            this.parabolaDirectriss = new GlLineR2(new GlPointR2(yFocus * SIN + systemCenter.X, -yFocus * COS + systemCenter.Y), new GlVectorR2(1, 0).getRotatedVector(-SIN, COS));

            for (int i = 0; i < 180; i++)
            {
                float SIN_A  = (float)Math.Sin(i * Math.PI / 180);
                float COS_A  = (float)Math.Cos(i * Math.PI / 180);
                float SINH_A = (float)Math.Sin(i * Math.PI / 360);
                float AbsedA = (float)Math.Abs(a);

                float PartRes  = (float)(Math.Sqrt(2 * AbsedA) * Math.Sqrt(2 * a * SIN_A * SIN_A - 8 * a * SINH_A * SINH_A + 8 * SINH_A * SINH_A * AbsedA));
                float fDevider = 8 * AbsedA * AbsedA - 4 * a * AbsedA + 4 * a * AbsedA * COS_A;

                float x1 = PartRes / fDevider;
                float x2 = PartRes / -fDevider;

                float y1 = a * x1 * x1;
                float y2 = a * x2 * x2;

                this.curvePoints[180 + i] = new GlPointR2(x1 * COS - y1 * SIN + systemCenter.X, x1 * SIN + y1 * COS + systemCenter.Y);
                this.curvePoints[179 - i] = new GlPointR2(x2 * COS - y2 * SIN + systemCenter.X, x2 * SIN + y2 * COS + systemCenter.Y);
            }
        }
Beispiel #3
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, this.polyCenter.X, this.polyCenter.Y))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, this.polyCenter.X, this.polyCenter.Y);
            }

            GlVectorR2 delta = new GlVectorR2(x - polyCenter.X, y - polyCenter.Y);

            for (int i = 0; i < vertexes.Length; i++)
            {
                vertexes[i] = delta.fromPointToPoint(vertexes[i]);
            }

            GlPointR2 OP = new GlPointR2(this.polyCenter);

            this.polyCenter = new GlPointR2(x, y);

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, OP.X, OP.Y);
            }
        }
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public override void moveTo(float x, float y)
        {
            float oldX = systemCenter.X, oldY = systemCenter.Y;

            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, oldX, oldY))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, oldX, oldY);
            }

            GlVectorR2 moveVector = new GlVectorR2(x - this.systemCenter.X, y - this.systemCenter.Y);

            this.systemCenter = new GlPointR2(x, y);

            foreach (GlFigure F in this.figuresAmount)
            {
                GlPointR2 newCenter = moveVector.fromPointToPoint(F.Center);
                F.moveTo(newCenter.X, newCenter.Y);
            }

            if (OnMoved != null)
            {
                OnMoving.Invoke(this, oldX, oldY);
            }
        }
Beispiel #5
0
        public override GlPointR2[] getIntersection(GlPolygon POLY)
        {
            if (POLY == null || POLY.CountOfPoints == 0)
            {
                return new GlPointR2[] { }
            }
            ;

            GlPointR2[] Intersections        = new GlPointR2[POLY.CountOfPoints];
            int         countOfIntersections = 0;

            GlPointR2[] faultInter = new GlLineR2(POLY[POLY.CountOfPoints - 1], new GlVectorR2(POLY[0].X - POLY[POLY.CountOfPoints - 1].X, POLY[0].Y - POLY[POLY.CountOfPoints - 1].Y)).getIntersection(this);

            if (faultInter.Length == 1 && new GlLineSegment(POLY[0], POLY[POLY.CountOfPoints - 1]).isPointBelongs(faultInter[0]))
            {
                Intersections[countOfIntersections++] = faultInter[0];
            }

            for (int i = 0; i < POLY.CountOfPoints - 1; i++)
            {
                faultInter = new GlLineR2(POLY[i], new GlVectorR2(POLY[i + 1].X - POLY[i].X, POLY[i + 1].Y - POLY[i].Y)).getIntersection(this);

                if (faultInter.Length == 1 && new GlLineSegment(POLY[i + 1], POLY[i]).isPointBelongs(faultInter[0]))
                {
                    Intersections[countOfIntersections++] = faultInter[0];
                }
            }

            GlPointR2[] result = new GlPointR2[countOfIntersections];
            Array.Copy(Intersections, result, countOfIntersections);
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Determines the position of given point in a rotated and parallel-moved coordinate system
        /// </summary>
        /// <param name="P">Point to be translated</param>
        /// <param name="SIN">sin of a counter-wise angle of system rotation</param>
        /// <param name="COS">cos of a counter-wise angle of system rotation</param>
        /// <param name="systemCenter">Center of the system point is being tanslated to</param>
        /// <returns>Translated point</returns>
        public GlPointR2 getPointTranslatedToRotatedSystem(float SIN, float COS, GlPointR2 systemCenter)
        {
            GlPointR2 TranslatedPoint = new GlPointR2(this);

            TranslatedPoint.moveTo((TranslatedPoint.X - systemCenter.X) * COS + (TranslatedPoint.Y - systemCenter.Y) * SIN, -(TranslatedPoint.X - systemCenter.X) * SIN + (TranslatedPoint.Y - systemCenter.Y) * COS);
            return(TranslatedPoint);
        }
Beispiel #7
0
        ///////////////////////////////////////////////
        ////////////////////FIELDS/////////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        /////////////////CONSTRUCTORS//////////////////
        ///////////////////////////////////////////////

        public GlHyperbola(float realHalfAxis, float additionalHalfAxis, GlVectorR2 xAxisDirection, GlPointR2 systemCenter)
        {
            this.curvePoints = new GlPointR2[179];

            if (xAxisDirection == null || systemCenter == null)
            {
                directVector = new GlVectorR2(0, 0);
                systemCenter = new GlPointR2(float.NaN, float.NaN);
                Ra           = 0;
                Rb           = 0;
                return;
            }

            this.directVector = xAxisDirection;
            this.systemCenter = systemCenter;

            this.Ra = realHalfAxis;
            this.Rb = additionalHalfAxis;

            if (directVector.isNullVector() || systemCenter.isNullPoint())
            {
                return;
            }

            updatePointsPosition();
        }
Beispiel #8
0
        /// <summary>
        /// Determines the position of given point in a standard coordinate system
        /// </summary>
        /// <param name="P">Point to be translated back</param>
        /// <param name="SIN">sin of a counter-wise angle of system rotation</param>
        /// <param name="COS">cos of a counter-wise angle of system rotation</param>
        /// <param name="systemCenter">Center of the system point was tanslated to</param>
        /// <returns>Translated back point</returns>
        public GlPointR2 getTranslatedBackPoint(float SIN, float COS, GlPointR2 systemCenter)
        {
            GlPointR2 TranslatedPoint = new GlPointR2(this);

            TranslatedPoint.moveTo(TranslatedPoint.X * COS - TranslatedPoint.Y * SIN + systemCenter.X, TranslatedPoint.X * SIN + TranslatedPoint.Y * COS + systemCenter.Y);
            return(TranslatedPoint);
        }
Beispiel #9
0
        //////////////TRANSFORM_METHODS////////////////
        ///////////////////////////////////////////////
        /////////////INTERSECTION_METHODS//////////////

        public override GlPointR2[] getIntersection(GlLineR2 L)
        {
            if (L == null || this.isNullParabola() || L.isNullLine())
            {
                return new GlPointR2[] { }
            }
            ;

            GlParabola PC  = new GlParabola(this.A, new GlPointR2(0, 0), new GlVectorR2(1, 0));
            GlPointR2  LP0 = L.PointOfLine.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Vertex);
            GlPointR2  LP1 = L.DirectVector.getRotatedVector(this.SIN, this.COS).fromPointToPoint(LP0);

            float fPartRes = LP0.Y - LP1.Y;
            float sPartRes = (float)Math.Sqrt(4 * PC.A * (LP0.X - LP1.X) * (LP0.X * LP1.Y - LP1.X * LP0.Y + PC.C * (LP1.X - LP0.X)) + (float)Math.Pow(PC.B * (LP0.X - LP1.X) - LP0.Y + LP1.Y, 2.0));
            float tPartRes = PC.B * (LP1.X - LP0.X);
            float devider  = 2 * PC.A * (LP0.X - LP1.X);

            float x1 = (fPartRes + sPartRes + tPartRes) / devider;
            float x2 = (fPartRes - sPartRes + tPartRes) / devider;

            float y1 = PC.A * x1 * x1 + PC.B * x1 + PC.C;
            float y2 = PC.A * x2 * x2 + PC.B * x2 + PC.C;

            return(new GlPointR2[] {
                new GlPointR2(x1, y1).getTranslatedBackPoint(this.SIN, this.COS, this.Vertex),
                new GlPointR2(x2, y2).getTranslatedBackPoint(this.SIN, this.COS, this.Vertex)
            });
        }
Beispiel #10
0
        ///////////////////////////////////////////////
        //////////////////PROPERTIES///////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        ////////////////////METHODS////////////////////
        ///////////////////////////////////////////////

        //////////////TRANSFORM_METHODS////////////////

        public void moveTo(GlPointR2 newBelongsPoint)
        {
            if (newBelongsPoint == null || newBelongsPoint.isNullPoint())
            {
                return;
            }

            if (OnMoveStart != null)
            {
                if (!OnMoveStart.Invoke(this, this.pointOfLine.X, this.pointOfLine.Y))
                {
                    return;
                }
            }

            if (OnMoving != null)
            {
                OnMoving.Invoke(this, this.pointOfLine.X, this.pointOfLine.Y);
            }

            GlPointR2 OP = new GlPointR2(this.PointOfLine);

            this.pointOfLine = newBelongsPoint;

            if (OnMoved != null)
            {
                OnMoved.Invoke(this, OP.X, OP.Y);
            }
        }
Beispiel #11
0
        ///////////////////////////////////////////////
        ////////////////////FIELDS/////////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        /////////////////CONSTRUCTORS//////////////////
        ///////////////////////////////////////////////

        /// <param name="R1">size of X half-axis</param>
        /// <param name="R2">size of Y half-axis</param>
        /// <param name="VectorR1">Vector of x-axis positive direction</param>
        /// <param name="OvalCenter">Point of the center of the oval</param>
        public GlOval(float R1, float R2, GlVectorR2 VectorR1, GlPointR2 OvalCenter)
        {
            this.curvePoints = new GlPointR2[360];

            if (VectorR1 == null || OvalCenter == null)
            {
                directVector = new GlVectorR2(0, 0);
                systemCenter = new GlPointR2(float.NaN, float.NaN);
                Ra           = 0;
                Rb           = 0;
                return;
            }

            this.systemCenter = new GlPointR2(OvalCenter);

            this.Ra = R1;
            this.Rb = R2;

            this.directVector = VectorR1;

            if (VectorR1.isNullVector())
            {
                return;
            }

            this.Length = (int)Math.Ceiling(Math.PI * Math.Sqrt(2 * (R1 * R1 + R2 * R2)));

            updatePointsPosition();
        }
Beispiel #12
0
        /////////////INSIDE_BELONGS_METHODS////////////
        ///////////////////////////////////////////////
        ///////////////ADDITIONAL_METHODS//////////////

        public virtual void AddVertex(GlPointR2 P)
        {
            if (P == null || P.isNullPoint())
            {
                return;
            }

            if (OnVertexAddingStart != null)
            {
                if (!OnVertexAddingStart.Invoke(P))
                {
                    return;
                }
            }

            if (OnVertexAdding != null)
            {
                OnVertexAdding.Invoke(P);
            }

            if (polyCenter == null)
            {
                polyCenter = P;
            }

            GlPointR2[] copy = this.vertexes;
            this.vertexes = new GlPointR2[this.vertexes.Length + 1];
            Array.Copy(copy, this.vertexes, copy.Length);
            this.vertexes[this.vertexes.Length - 1] = P;

            if (OnVertexAdded != null)
            {
                OnVertexAdded.Invoke(P);
            }
        }
Beispiel #13
0
        //////////////TRANSFORM_METHODS////////////////
        ///////////////////////////////////////////////
        /////////////INTERSECTION_METHODS//////////////

        public override GlPointR2[] getIntersection(GlLineR2 L)
        {
            if (!this.isIntersects(L))
            {
                return new GlPointR2[] { }
            }
            ;

            GlPointR2[] Intersections  = new GlPointR2[2];
            GlPointR2   LineMovedPoint = L.PointOfLine.getPointTranslatedToRotatedSystem(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY));
            GlLineR2    IL             = new GlLineR2(LineMovedPoint, L.DirectVector.getRotatedVector(this.SIN, this.COS));

            float Devider = (float)(Math.Pow(this.RadA * IL.DirectVector.deltaY, 2.0) + Math.Pow(this.RadB * IL.DirectVector.deltaX, 2.0));
            float PartRes = (float)Math.Sqrt(Math.Pow(this.RadA * IL.DirectVector.deltaY, 2.0) + Math.Pow(this.RadB * IL.DirectVector.deltaX, 2.0) - Math.Pow(IL.PointOfLine.X * IL.DirectVector.deltaY, 2.0) + (double)(2 * IL.PointOfLine.X * IL.PointOfLine.Y * IL.DirectVector.deltaX * IL.DirectVector.deltaY) - Math.Pow(IL.DirectVector.deltaX * IL.PointOfLine.Y, 2.0));

            float xPart = this.RadA * IL.PointOfLine.X * (float)Math.Pow(IL.DirectVector.deltaY, 2.0) - this.RadA * IL.DirectVector.deltaX * IL.DirectVector.deltaY * IL.PointOfLine.Y;
            float yPart = this.RadB * IL.PointOfLine.Y * (float)Math.Pow(IL.DirectVector.deltaX, 2.0) - this.RadB * IL.DirectVector.deltaX * IL.DirectVector.deltaY * IL.PointOfLine.X;

            float xC1 = this.RadA * (this.RadB * IL.DirectVector.deltaX * PartRes + xPart) / Devider;
            float yC1 = this.RadB * (this.RadA * IL.DirectVector.deltaY * PartRes + yPart) / Devider;

            float xC2 = -this.RadA * (this.RadB * IL.DirectVector.deltaX * PartRes - xPart) / Devider;
            float yC2 = -this.RadB * (this.RadA * IL.DirectVector.deltaY * PartRes - yPart) / Devider;

            Intersections[0] = new GlPointR2(xC1, yC1).getTranslatedBackPoint(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY));
            Intersections[1] = new GlPointR2(xC2, yC2).getTranslatedBackPoint(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY));

            return(Intersections);
        }
Beispiel #14
0
        ///////////////////////////////////////////////
        /////////////////CONSTRUCTORS//////////////////
        ///////////////////////////////////////////////

        public GlTriangle(GlPointR2 P1, GlPointR2 P2, GlPointR2 P3) :
            base((P1 == null || P2 == null || P3 == null)?
                 new GlPointR2(float.NaN, float.NaN) :
                 new GlPointR2((P1.X + P2.X + P3.X) / 3, (P1.Y + P2.Y + P3.Y) / 3),
                 new GlPointR2[] { P1, P2, P3 })
        {
            this.S = Math.Abs((P1.X - P3.X) * (P2.Y - P3.Y) - (P1.Y - P3.Y) * (P2.X - P3.X)) / 2;
        }
Beispiel #15
0
        public GlLineR2 getParallel(GlPointR2 P)
        {
            if (P == null || this.pointOfLine.isNullPoint() || P.isNullPoint())
            {
                return(null);
            }

            return(new GlLineR2(P, this.DirectVector));
        }
Beispiel #16
0
        public GlLineR2 getPerpendicular(GlPointR2 P)
        {
            GlPointR2 projection = this.getProjection(P);

            if (projection == null)
            {
                return(null);
            }

            return(new GlLineR2(projection, new GlVectorR2(projection.X - P.X, projection.Y - P.Y)));
        }
Beispiel #17
0
        public override bool isPointBelongs(GlPointR2 P)
        {
            if (P == null || P.isNullPoint())
            {
                return(false);
            }

            GlPointR2 TP = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Center);

            return(Math.Abs(TP.X - RealHalfAixis * Math.Sqrt(TP.Y * TP.Y + Math.Pow(AdditionalHalfAixis, 2.0)) / AdditionalHalfAixis) < FAULT);
        }
Beispiel #18
0
        ////////////////TANGENT_METHODS////////////////
        ///////////////////////////////////////////////
        /////////////INSIDE_BELONGS_METHODS////////////

        public override bool isPointInside(GlPointR2 P)
        {
            if (P == null || P.isNullPoint())
            {
                return(false);
            }

            GlPointR2 TP = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Center);

            return(Math.Pow(TP.X / RealHalfAixis, 2.0) - Math.Pow(TP.Y / AdditionalHalfAixis, 2.0) - 1 > -FAULT);
        }
        ////////////INTERSECTION_METHODS///////////////
        ///////////////////////////////////////////////
        /////////////INSIDE_BELONGS_METHODS////////////

        public override bool isPointBelongs(GlPointR2 P)
        {
            foreach (GlFigure F in figuresAmount)
            {
                if (F.isPointBelongs(P))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #20
0
        public override bool isPointBelongs(GlPointR2 P)
        {
            if (P == null || P.isNullPoint())
            {
                return(false);
            }

            GlPointR2 LineMovedPoint = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY));

            return(Math.Abs(Math.Pow(LineMovedPoint.X / this.RadA, 2.0) + Math.Pow(LineMovedPoint.Y / this.RadB, 2.0) - 1) < FAULT);
        }
Beispiel #21
0
        public override bool isPointBelongs(GlPointR2 P)
        {
            if (P == null || P.isNullPoint())
            {
                return(false);
            }

            GlPointR2  RP  = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Vertex);
            GlParabola RPB = new GlParabola(this.A, new GlPointR2(0, 0), new GlVectorR2(1, 0));

            return(Math.Abs(RP.Y - RPB.A * RP.X * RP.X - RPB.B * RP.X - RPB.C) < FAULT);
        }
Beispiel #22
0
        ///////////////////////////////////////////////
        ////////////////////FIELDS/////////////////////
        ///////////////////////////////////////////////


        /*********************************************/


        ///////////////////////////////////////////////
        /////////////////CONSTRUCTORS//////////////////
        ///////////////////////////////////////////////

        public GlLineR2(GlPointR2 belongsPoint, GlVectorR2 directVector)
        {
            if (belongsPoint == null || directVector == null)
            {
                this.directVector = new GlVectorR2(0, 0);
                pointOfLine       = new GlPointR2(float.NaN, float.NaN);
                return;
            }

            this.pointOfLine  = belongsPoint;
            this.directVector = directVector;
        }
Beispiel #23
0
        /////////////INTERSECTION_METHODS//////////////
        ///////////////////////////////////////////////
        ////////////////TANGENT_METHODS////////////////

        public GlLineR2[] getTangentFromPoint(GlPointR2 P)
        {
            if (P == null || P.isNullPoint() || this.isPointInside(P))
            {
                return new GlLineR2[] { }
            }
            ;

            GlOval    IO         = new GlOval(this.RadA, this.RadB, new GlVectorR2(this.RadA, 0.0f), new GlPointR2(0.0f, 0.0f));
            GlPointR2 MovedPoint = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY));

            if (this.RadA > this.RadB)
            {
                IO = new GlOval(this.RadB, this.RadA, this.directVector.getRotatedVector((float)Math.PI / 2), new GlPointR2(0.0f, 0.0f));

                MovedPoint.moveTo(MovedPoint.Y, -MovedPoint.X);
            }

            float Devider  = (float)(Math.Pow(IO.RadA * MovedPoint.Y, 2.0) + Math.Pow(IO.RadB * MovedPoint.X, 2.0));
            float fPartRes = (float)Math.Pow(IO.RadA, 3.0) * IO.RadB * MovedPoint.X;
            float sPartRes = IO.RadA * IO.RadA * MovedPoint.Y * (float)Math.Sqrt(Math.Abs(-Math.Pow(IO.RadA, 4.0) + Math.Pow(IO.RadA * MovedPoint.Y, 2.0) + Math.Pow(IO.RadB * MovedPoint.X, 2.0)));

            float xI1 = (fPartRes + sPartRes) / Devider;
            float xI2 = (fPartRes - sPartRes) / Devider;

            float yI1 = (MovedPoint.X < 0 ? 1 : -1) * IO.RadB * (float)Math.Sqrt(Math.Abs(IO.RadA * IO.RadA - xI1 * xI1)) / IO.RadA;
            float yI2 = (MovedPoint.X < 0 ? -1 : 1) * IO.RadB * (float)Math.Sqrt(Math.Abs(IO.RadA * IO.RadA - xI2 * xI2)) / IO.RadA;

            if (Math.Abs(MovedPoint.X) < IO.RadA)
            {
                yI1 = (MovedPoint.Y < 0 && yI1 >= 0) ? -Math.Abs(yI1) : ((MovedPoint.Y > 0 && yI1 < 0) ? Math.Abs(yI1) : yI1);
                yI2 = (MovedPoint.Y < 0 && yI2 >= 0) ? -Math.Abs(yI2) : ((MovedPoint.Y > 0 && yI2 < 0) ? Math.Abs(yI2) : yI2);
            }

            if (this.RadA > this.RadB)
            {
                float temp = xI1;
                xI1 = -yI1;
                yI1 = temp;

                temp = xI2;
                xI2  = -yI2;
                yI2  = temp;
            }

            GlPointR2 P1 = new GlPointR2(xI1, yI1).getTranslatedBackPoint(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY));
            GlPointR2 P2 = new GlPointR2(xI2, yI2).getTranslatedBackPoint(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY));

            return(new GlLineR2[] {
                new GlLineR2(P1, new GlVectorR2(P1.X - P.X, P1.Y - P.Y)),
                new GlLineR2(P2, new GlVectorR2(P2.X - P.X, P2.Y - P.Y))
            });
        }
Beispiel #24
0
        ////////////////DRAW_METHODS///////////////////
        ///////////////////////////////////////////////
        /////////////INSIDE_BELONGS_METHODS////////////

        public bool isPointInside(GlPointR2 P)
        {
            float SP = 0;

            for (int i = 0; i < this.CountOfPoints - 1; i++)
            {
                SP += new GlTriangle(P, this.vertexes[i], this.vertexes[i + 1]).S;
            }
            SP += new GlTriangle(P, this.vertexes[this.CountOfPoints - 1], this.vertexes[0]).S;

            return(Math.Abs(SP - S) < FAULT);
        }
Beispiel #25
0
        /////////////INTERSECTION_METHODS//////////////
        ///////////////////////////////////////////////
        ////////////////TANGENT_METHODS////////////////

        public override GlLineR2 getTangentFromBelongs(GlPointR2 P)
        {
            if (P == null || !this.isPointBelongs(P))
            {
                return(new GlLineR2(new GlPointR2(null), new GlVectorR2(null)));
            }

            GlPointR2 TP = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Center);
            float     k  = (TP.Y >= 0 ? 1 : -1) * AdditionalHalfAixis * TP.X / (RealHalfAixis * (float)Math.Sqrt(TP.X * TP.X - Math.Pow(RealHalfAixis, 2.0)));

            GlLineR2 tangent = new GlLineR2(P, new GlVectorR2(1, 0).getRotatedVector((float)Math.Atan(k)));

            tangent.Rotate(this.SIN, this.COS);
            return(tangent);
        }
Beispiel #26
0
        public GlPointR2 getProjection(GlPointR2 P)
        {
            if (P == null || this.PointOfLine.isNullPoint() || P.isNullPoint())
            {
                return(new GlPointR2(null));
            }

            if (this.DirectVector.isNullVector())
            {
                return(this.pointOfLine);
            }

            float both = (this.DirectVector.deltaX * (P.X - this.pointOfLine.X) + this.DirectVector.deltaY * (P.Y - this.pointOfLine.Y)) / (float)Math.Pow(this.DirectVector.Length, 2.0);

            return(new GlPointR2(this.DirectVector.deltaX * both + this.pointOfLine.X, this.DirectVector.deltaY * both + this.pointOfLine.Y));
        }
Beispiel #27
0
        public override GlLineR2 getTangentFromBelongs(GlPointR2 P)
        {
            if (P == null || P.isNullPoint() || !this.isPointBelongs(P) || this.RadA == 0.0f)
            {
                return(new GlLineR2(new GlPointR2(null), new GlVectorR2(null)));
            }

            GlOval    IO         = new GlOval(this.RadA, this.RadB, new GlVectorR2(this.RadA, 0.0f), new GlPointR2(0.0f, 0.0f));
            GlPointR2 MovedPoint = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY));

            GlLineR2 tangent = new GlLineR2(MovedPoint, new GlVectorR2(-(float)Math.Pow(this.RadA, 2.0) * MovedPoint.Y, (float)Math.Pow(this.RadB, 2.0) * MovedPoint.X));

            tangent.Rotate(this.SIN, this.COS);
            tangent.moveTo(P);

            return(tangent);
        }
Beispiel #28
0
        /////////////INTERSECTION_METHODS//////////////
        ///////////////////////////////////////////////
        ////////////////TANGENT_METHODS////////////////

        public override GlLineR2 getTangentFromBelongs(GlPointR2 P)
        {
            if (P == null || P.isNullPoint())
            {
                return(new GlLineR2(new GlPointR2(null), new GlVectorR2(null)));
            }

            GlParabola TPB = new GlParabola(this.A, new GlPointR2(0, 0), new GlVectorR2(1, 0));
            GlPointR2  TP  = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Vertex);

            float k = 2 * TPB.A * TP.X + TPB.B;

            GlLineR2 tangent = new GlLineR2(P, new GlVectorR2(1, 0).getRotatedVector((float)Math.Atan(k)));

            tangent.Rotate(this.SIN, this.COS);
            return(tangent);
        }
Beispiel #29
0
        public override GlFigure getScaled(float scale)
        {
            GlPointR2 C = new GlPointR2(this.Center);

            C.moveTo(C.X * scale, C.Y * scale);

            GlPolygon PR = new GlPolygon(C);

            for (int i = 0; i < this.CountOfPoints; i++)
            {
                GlPointR2 P = this[i];
                P.moveTo(P.X * scale, P.Y * scale);
                PR.AddVertex(new GlPointR2(P));
            }

            PR.moveTo(this.Center.X, this.Center.Y);
            return(PR);
        }
Beispiel #30
0
        //////////////TRANSFORM_METHODS////////////////
        ///////////////////////////////////////////////
        /////////////INTERSECTION_METHODS//////////////

        public override GlPointR2[] getIntersection(GlLineR2 L)
        {
            GlVectorR2 translatedVector = new GlVectorR2(L.DirectVector).getRotatedVector(this.SIN, this.COS);
            GlPointR2  FP = L.PointOfLine.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Center);
            GlPointR2  SP = translatedVector.fromPointToPoint(FP);

            float fPartRes = (float)Math.Pow(AdditionalHalfAixis * (FP.X - SP.X), 2.0);
            float sPartRes = (float)Math.Pow(RealHalfAixis * (FP.Y - SP.Y), 2.0);
            float tPartRes = FP.X * SP.Y - SP.X * FP.Y;
            float sqrtPart = RealHalfAixis * AdditionalHalfAixis * (FP.X - SP.X) * (float)Math.Sqrt(fPartRes - sPartRes + Math.Pow(tPartRes, 2.0));

            float x1 = (-(float)Math.Pow(RealHalfAixis, 2.0) * (FP.Y - SP.Y) * tPartRes + sqrtPart) / (sPartRes - fPartRes);
            float x2 = (-(float)Math.Pow(RealHalfAixis, 2.0) * (FP.Y - SP.Y) * tPartRes - sqrtPart) / (sPartRes - fPartRes);

            float y1 = AdditionalHalfAixis * (float)Math.Sqrt(x1 * x1 - Math.Pow(RealHalfAixis, 2.0)) / RealHalfAixis;
            float y2 = -AdditionalHalfAixis * (float)Math.Sqrt(x2 * x2 - Math.Pow(RealHalfAixis, 2.0)) / RealHalfAixis;

            float y3 = -AdditionalHalfAixis * (float)Math.Sqrt(x1 * x1 - Math.Pow(RealHalfAixis, 2.0)) / RealHalfAixis;
            float y4 = AdditionalHalfAixis * (float)Math.Sqrt(x2 * x2 - Math.Pow(RealHalfAixis, 2.0)) / RealHalfAixis;

            GlPointR2[] RP =
            {
                new GlPointR2(x1, y1).getTranslatedBackPoint(this.SIN, this.COS, this.Center),
                new GlPointR2(x2, y2).getTranslatedBackPoint(this.SIN, this.COS, this.Center),
                new GlPointR2(x1, y3).getTranslatedBackPoint(this.SIN, this.COS, this.Center),
                new GlPointR2(x2, y4).getTranslatedBackPoint(this.SIN, this.COS, this.Center)
            };

            List <GlPointR2> res = new List <GlPointR2>();

            for (int i = 0; i < RP.Length; i++)
            {
                bool a = this.isPointBelongs(RP[i]);
                bool b = L.isPointBelongs(RP[i]);
                if (a && b)
                {
                    res.Add(RP[i]);
                }
            }

            return(res.ToArray());
        }