Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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)
            });
        }
Exemplo n.º 3
0
        public override GlPointR2[] getIntersection(GlPolygon POLY)
        {
            List <GlPointR2> Intersections = new List <GlPointR2>();

            GlLineR2 fCurLine = new GlLineR2(this[this.CountOfPoints - 1], new GlVectorR2(this[0].X - this[this.CountOfPoints - 1].X, this[0].Y - this[this.CountOfPoints - 1].Y));

            GlPointR2[] faultInter = fCurLine.getIntersection(POLY);
            foreach (GlPointR2 j in faultInter)
            {
                if (new GlLineSegment(this[this.CountOfPoints - 1], this[0]).isPointBelongs(j))
                {
                    Intersections.Add(j);
                }
            }

            for (int i = 0; i < this.CountOfPoints - 1; i++)
            {
                fCurLine   = new GlLineR2(this[i], new GlVectorR2(this[i + 1].X - this[i].X, this[i + 1].Y - this[i].Y));
                faultInter = fCurLine.getIntersection(POLY);
                foreach (GlPointR2 j in faultInter)
                {
                    if (new GlLineSegment(this[i], this[i + 1]).isPointBelongs(j))
                    {
                        Intersections.Add(j);
                    }
                }
            }

            return(Intersections.ToArray());
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        /// <returns>If the line intersects the oval</returns>
        public bool isIntersects(GlLineR2 L)
        {
            if (L == null || L.isNullLine())
            {
                return(false);
            }

            GlVectorR2 LV = L.DirectVector.getRotatedVector(this.SIN, this.COS);

            return(Math.Pow(this.RadA * LV.deltaY, 2.0) + Math.Pow(this.RadB * LV.deltaX, 2.0) != 0);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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());
        }
Exemplo n.º 11
0
        //////////////TRANSFORM_METHODS////////////////
        ///////////////////////////////////////////////
        /////////////INTERSECTION_METHODS//////////////

        /// <summary>
        /// Determines the intersection of a point and a line
        /// </summary>
        /// <returns>An array containing a copy of given point if it belongs to the line</returns>
        public override GlPointR2[] getIntersection(GlLineR2 L)
        {
            return(L == null ? new GlPointR2[] { } : L.getIntersection(this));
        }
Exemplo n.º 12
0
 /// <summary>
 /// Determines an anmount of points, created by intersection of a figure and a line
 /// </summary>
 /// <returns>An array of intersections</returns>
 public abstract GlPointR2[] getIntersection(GlLineR2 L);
Exemplo n.º 13
0
        private void DrawPoints(GlRectangle Border, int GlDrawMode)
        {
            if (Border == null || !ActivateDrawStart())
            {
                return;
            }

            ActivateDrawing();

            bool isInside = Border.isPointInside(this[0]);

            GlPolygon ToDraw = new GlPolygon(this.Center);

            if (Border.isPointInside(this[this.CountOfPoints - 1]) != isInside)
            {
                if (!isInside)
                {
                    ToDraw.AddVertex(this[this.CountOfPoints - 1]);
                }

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

                if (I.Length == 2)
                {
                    ToDraw.AddVertex(new GlLineSegment(this[this.CountOfPoints - 1], this[0]).isPointBelongs(I[0]) ? I[0] : I[1]);
                }
                else if (I.Length == 1 && new GlLineSegment(this[this.CountOfPoints - 1], this[0]).isPointBelongs(I[0]))
                {
                    ToDraw.AddVertex(I[0]);
                }
            }

            for (int i = 0; i < this.CountOfPoints - 1; i++)
            {
                if (isInside)
                {
                    ToDraw.AddVertex(this[i]);
                }
                if (Border.isPointInside(this[i + 1]) != isInside)
                {
                    GlPointR2[] I = new GlLineR2(this[i], new GlVectorR2(this[i + 1].X - this[i].X,
                                                                         this[i + 1].Y - this[i].Y)).getIntersection(Border);

                    if (I.Length == 2)
                    {
                        ToDraw.AddVertex(new GlLineSegment(this[i], this[i + 1]).isPointBelongs(I[0]) ? I[0] : I[1]);
                    }
                    else if (I.Length == 1 && new GlLineSegment(this[i], this[i + 1]).isPointBelongs(I[0]))
                    {
                        ToDraw.AddVertex(I[0]);
                    }

                    isInside = !isInside;
                }
            }

            Gl.glBegin(GlDrawMode);
            for (int i = 0; i < ToDraw.CountOfPoints; i++)
            {
                if (ToDraw[i] != null)
                {
                    Gl.glVertex2f(ToDraw[i].X, ToDraw[i].Y);
                }
            }
            Gl.glEnd();

            ActivateDrawed();
        }
Exemplo n.º 14
0
 public static bool Equals(GlLineR2 L1, GlLineR2 L2)
 {
     return((L1 == null || L2 == null || L1.isNullLine() || L2.isNullLine()) ? false : GlVectorR2.isParallel(L1.DirectVector, L2.DirectVector) && GlVectorR2.isParallel(L1.DirectVector, new GlVectorR2(L2.pointOfLine.X - L1.pointOfLine.X, L2.pointOfLine.Y - L1.pointOfLine.Y)));
 }
Exemplo n.º 15
0
 public GlLineR2(GlLineR2 copyLine) :
     this(copyLine == null ? new GlPointR2(float.NaN, float.NaN) : copyLine.PointOfLine,
          copyLine == null ? new GlVectorR2(0, 0) : copyLine.DirectVector)
 {
 }
Exemplo n.º 16
0
        //////////////TRANSFORM_METHODS////////////////
        ///////////////////////////////////////////////
        /////////////INTERSECTION_METHODS//////////////

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

            if (GlPointR2.Equals(this.pointOfLine, L.pointOfLine))//already have a result
            {
                return new GlPointR2[] { new GlPointR2(L.pointOfLine) }
            }
            ;

            bool isL1Point = this.DirectVector.isNullVector();
            bool isL2Point = L.DirectVector.isNullVector();

            if (isL1Point && isL2Point)//same points were catched in previous step
            {
                return new GlPointR2[] { }
            }
            ;

            if (this.DirectVector.isNullVector() && L.isPointBelongs(this.pointOfLine))//line and a point
            {
                return new GlPointR2[] { new GlPointR2(this.pointOfLine) }
            }
            ;

            if (L.DirectVector.isNullVector() && this.isPointBelongs(L.pointOfLine))//line and a point
            {
                return new GlPointR2[] { new GlPointR2(L.pointOfLine) }
            }
            ;

            if (GlLineR2.Equals(this, L))//lines are identical
            {
                return new GlPointR2[] { new GlPointR2(this.pointOfLine), new GlPointR2(L.PointOfLine) }
            }
            ;

            if (GlVectorR2.isParallel(this.DirectVector, L.DirectVector))//lines are parallel
            {
                return new GlPointR2[] { }
            }
            ;

            if (L.DirectVector.deltaX == 0)//L2 is parallel to Y axis
            {
                return new GlPointR2[] { new GlPointR2(L.pointOfLine.X, this.DirectVector.deltaY * (L.pointOfLine.X - this.pointOfLine.X) / this.DirectVector.deltaX + this.pointOfLine.Y) }
            }
            ;

            if (this.DirectVector.deltaY == 0)//L1 is parallel to X axis
            {
                return new GlPointR2[] { new GlPointR2(L.DirectVector.deltaX * (this.pointOfLine.Y - L.pointOfLine.Y) / L.DirectVector.deltaY + L.pointOfLine.X, this.pointOfLine.Y) }
            }
            ;

            float v2RatYX = L.DirectVector.deltaY / L.DirectVector.deltaX;
            float v1RatXY = this.DirectVector.deltaX / this.DirectVector.deltaY;
            float yInter  = (v1RatXY * v2RatYX * this.pointOfLine.Y - v2RatYX * this.pointOfLine.X + v2RatYX * L.pointOfLine.X - L.pointOfLine.Y) / (v1RatXY * v2RatYX - 1);
            float xInter  = v1RatXY * (yInter - this.pointOfLine.Y) + this.pointOfLine.X;

            return(new GlPointR2[] { new GlPointR2(xInter, yInter) });//common situation
        }