コード例 #1
0
 /// <summary>
 /// Copying constructor
 /// </summary>
 public GlOval(GlOval copyOval) :
     this(copyOval == null ? 0 : copyOval.RadA,
          copyOval == null ? 0 : copyOval.RadB,
          copyOval == null ? new GlVectorR2(0, 0) : copyOval.directVector,
          copyOval == null ? new GlPointR2(float.NaN, float.NaN) : new GlPointR2(copyOval.CenterX, copyOval.CenterY))
 {
 }
コード例 #2
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))
            });
        }
コード例 #3
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);
        }