Esempio n. 1
0
        public static float Cos(VectorF first, VectorF second)
        {
            if (first.Length() == 0 || second.Length() == 0)
            {
                return(0);
            }

            return(ScalarMultiply(first, second) / (first.Length() * second.Length()));
        }
Esempio n. 2
0
        public static bool IsSegmentIntersectsWithCircle(VectorF O, float Radius, VectorF A, VectorF B)
        {
            VectorF p1, p2;

            if (IsLineIntersectsWithCircle(O, Radius, A, B, out p1, out p2) == false)
            {
                return(false);
            }

            return((IsPointOnSegment(p1.X, A.X, B.X) && IsPointOnSegment(p1.Y, A.Y, B.Y)) ||
                   (IsPointOnSegment(p2.X, A.X, B.X) && IsPointOnSegment(p2.Y, A.Y, B.Y)));
        }
Esempio n. 3
0
        public static float AngleRad(VectorF first, VectorF second)
        {
            double angle1 = Math.Atan2(first.Y, first.X);

            if (angle1 < 0)
            {
                angle1 += 2 * Math.PI;
            }
            double angle2 = Math.Atan2(second.Y, second.X);

            if (angle2 < 0)
            {
                angle2 += 2 * Math.PI;
            }
            return((float)Math.Abs(angle1 - angle2));
        }
Esempio n. 4
0
        public static EdgeType GetEdgeType(VectorF point, VectorF s, VectorF e)
        {
            switch (Classify(s, e, point))
            {
            case PointPosition.LEFT:
                return(((s.Y < point.Y) && (point.Y <= e.Y)) ? EdgeType.CROSSING : EdgeType.INESSENTIAL);

            case PointPosition.RIGHT:
                return(((e.Y < point.Y) && (point.Y <= s.Y)) ? EdgeType.CROSSING : EdgeType.INESSENTIAL);

            case PointPosition.BETWEEN:
            case PointPosition.ORIGIN:
            case PointPosition.DESTINATION:
                return(EdgeType.TOUCHING);

            default:
                return(EdgeType.INESSENTIAL);
            }
        }
Esempio n. 5
0
        public bool IsPointInPoly(VectorF point)
        {
            int  i, j;
            bool c = false;

            for (i = 0, j = Points.Count - 1; i < Points.Count; i++)
            {
                switch (SimpleGeometry.GetEdgeType(point, Points[i] + Position, Points[j] + Position))
                {
                case SimpleGeometry.EdgeType.TOUCHING:
                    return(true);

                case SimpleGeometry.EdgeType.CROSSING:
                    c = !c;
                    break;
                }
                j = i;
            }

            return(c);
        }
Esempio n. 6
0
        public static bool IsLineIntersectsWithCircle(VectorF O, float Radius, VectorF A, VectorF B, out VectorF p1, out VectorF p2)
        {
            if (Math.Abs(A.X - B.X) < float.Epsilon)
            {
                p1 = new VectorF(A.X, -(float)Math.Sqrt(Radius * Radius - Math.Pow(A.X - O.X, 2)) + O.Y);
                p2 = new VectorF(A.X, (float)Math.Sqrt(Radius * Radius - Math.Pow(A.X - O.X, 2)) + O.Y);
                return(Math.Abs(O.X - A.X) < Radius);
            }
            if (Math.Abs(A.Y - B.Y) < float.Epsilon)
            {
                p1 = new VectorF(-(float)Math.Sqrt(Radius * Radius - Math.Pow(A.Y - O.Y, 2)) + O.X, A.Y);
                p2 = new VectorF((float)Math.Sqrt(Radius * Radius - Math.Pow(A.Y - O.Y, 2)) + O.X, A.Y);
                return(Math.Abs(O.Y - A.Y) < Radius);
            }

            float k = (B.Y - A.Y) / (B.X - A.X);
            float b = (A.Y - O.Y) - (A.X - O.X) * k;
            float D = 4 * b * b * k * k - 4 * (k * k + 1) * (b * b - Radius * Radius);

            if (D >= 0)
            {
                float x1 = (-2 * b * k - (float)Math.Sqrt(D)) / (2 * (k * k + 1)) + O.X;
                float x2 = (-2 * b * k + (float)Math.Sqrt(D)) / (2 * (k * k + 1)) + O.X;
                b  = A.Y - A.X * k;
                p1 = new VectorF(x1, k * x1 + b);
                p2 = new VectorF(x2, k * x2 + b);
                return(true);
            }

            p1 = p2 = new VectorF(float.NaN, float.NaN);
            return(false);
        }
Esempio n. 7
0
 public BoxCollision(VectorF Position, VectorF Size) : base(Position)
 {
     this.Size = Size;
 }
Esempio n. 8
0
 public static float ScalarMultiply(VectorF first, VectorF second)
 {
     return(first.X * second.X + first.Y * second.Y);
 }
Esempio n. 9
0
 public bool Equals(VectorF vector)
 {
     return((Math.Abs(X - vector.X) < float.Epsilon) && (Math.Abs(Y - vector.Y) < float.Epsilon));
 }
Esempio n. 10
0
 public static float AngleDeg(VectorF first, VectorF second)
 {
     return((float)(AngleRad(first, second) * 180 / Math.PI));
 }
Esempio n. 11
0
 public PolygonCollision(VectorF Position) : base(Position)
 {
     Vertex   = new List <VectorF>();
     Points   = new List <VectorF>();
     Rotation = 0.0f;
 }
Esempio n. 12
0
 public CircleCollision(VectorF Position, float Radius) : base(Position)
 {
     this.Radius = Radius;
 }
Esempio n. 13
0
 public Collision(VectorF Position)
 {
     this.Position = Position;
 }
Esempio n. 14
0
 public MacroCollisionRect(VectorF Position, VectorF Size)
 {
     this.Position = Position;
     this.Size     = Size;
 }