コード例 #1
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());
        }
コード例 #2
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
        }