public static bool TestIfPointInsideAnOrientedRectangle(RectangleOriented rectangle, PointD point)
        {
            /// Whe simply make the dot product with each angle
            Tuple <PointD, PointD, PointD, PointD> corners = GetCornerOfAnOrientedRectangle(rectangle);

            PointD a = corners.Item1;
            PointD b = corners.Item2;
            PointD c = corners.Item3;

            PointD vector_a_b     = new PointD(b.X - a.X, b.Y - a.Y);
            PointD vector_a_c     = new PointD(c.X - a.X, c.Y - a.Y);
            PointD vector_a_point = new PointD(point.X - a.X, point.Y - a.Y);

            double dot_product_point_b = (vector_a_b.X * vector_a_point.X) + (vector_a_b.Y * vector_a_point.Y);
            double dot_product_point_c = (vector_a_c.X * vector_a_point.X) + (vector_a_c.Y * vector_a_point.Y);

            double dot_product_b_b = Math.Pow(vector_a_b.X, 2) + Math.Pow(vector_a_b.Y, 2);
            double dot_product_c_c = Math.Pow(vector_a_c.X, 2) + Math.Pow(vector_a_c.Y, 2);

            return(dot_product_point_b >= 0 && dot_product_point_c >= 0 && dot_product_point_b <= dot_product_b_b && dot_product_point_c <= dot_product_c_c);
        }
        public static Tuple <PointD, PointD, PointD, PointD> GetCornerOfAnOrientedRectangle(RectangleOriented rectangle)
        {
            double radius_of_the_circle = Math.Sqrt(Math.Pow(rectangle.Width, 2) + Math.Pow(rectangle.Lenght, 2)) / 2;


            double angle_1 = ModuloPiAngleRadian(Math.Atan2(rectangle.Lenght, rectangle.Width) + rectangle.Angle);
            double angle_2 = ModuloPiAngleRadian(Math.Atan2(-rectangle.Lenght, rectangle.Width) + rectangle.Angle);

            if (angle_1 < 0)
            {
                SwapNum(ref angle_1, ref angle_2);
            }

            PointD polar_a_1 = ConvertPolarToPointD(new PolarPointRssi(angle_1, radius_of_the_circle, 0));
            PointD polar_a_2 = ConvertPolarToPointD(new PolarPointRssi(angle_2, radius_of_the_circle, 0));
            PointD polar_a_3 = ConvertPolarToPointD(new PolarPointRssi(angle_2, -radius_of_the_circle, 0));
            PointD polar_a_4 = ConvertPolarToPointD(new PolarPointRssi(angle_1, -radius_of_the_circle, 0));

            if (polar_a_1.Y < 0)
            {
                SwapNum(ref polar_a_1, ref polar_a_2);
                SwapNum(ref polar_a_3, ref polar_a_4);
            }


            PointD a1 = new PointD(polar_a_1.X + rectangle.Center.X, polar_a_1.Y + rectangle.Center.Y);
            PointD a2 = new PointD(polar_a_2.X + rectangle.Center.X, polar_a_2.Y + rectangle.Center.Y);
            PointD a3 = new PointD(polar_a_3.X + rectangle.Center.X, polar_a_3.Y + rectangle.Center.Y);
            PointD a4 = new PointD(polar_a_4.X + rectangle.Center.X, polar_a_4.Y + rectangle.Center.Y);

            return(new Tuple <PointD, PointD, PointD, PointD>(a1, a2, a3, a4));
        }
Esempio n. 3
0
        public static Tuple <PointD, PointD, PointD, PointD> GetCornerOfAnOrientedRectangle(RectangleOriented rectangle)
        {
            double radius_of_the_circle = Math.Sqrt(Math.Pow(rectangle.Lenght, 2) + Math.Pow(rectangle.Width, 2)) / 2;
            double a_1_angle            = Modulo2PiAngleRad(Math.Atan2(rectangle.Width, rectangle.Lenght) + rectangle.Angle);
            double a_3_angle            = Modulo2PiAngleRad(Math.Atan2(rectangle.Width, -rectangle.Lenght) + rectangle.Angle);
            double a_2_angle            = Modulo2PiAngleRad(Math.Atan2(-rectangle.Width, rectangle.Lenght) + rectangle.Angle);
            double a_4_angle            = Modulo2PiAngleRad(Math.Atan2(-rectangle.Width, -rectangle.Lenght) + rectangle.Angle);

            PointD polar_a_1 = ConvertPolarToPointD(new PolarPointRssi(a_1_angle, radius_of_the_circle, 0));
            PointD polar_a_2 = ConvertPolarToPointD(new PolarPointRssi(a_2_angle, radius_of_the_circle, 0));
            PointD polar_a_3 = ConvertPolarToPointD(new PolarPointRssi(a_3_angle, radius_of_the_circle, 0));
            PointD polar_a_4 = ConvertPolarToPointD(new PolarPointRssi(a_4_angle, radius_of_the_circle, 0));

            PointD a1 = new PointD(polar_a_1.X + rectangle.Center.X, polar_a_1.Y + rectangle.Center.Y);
            PointD a2 = new PointD(polar_a_2.X + rectangle.Center.X, polar_a_2.Y + rectangle.Center.Y);
            PointD a3 = new PointD(polar_a_3.X + rectangle.Center.X, polar_a_3.Y + rectangle.Center.Y);
            PointD a4 = new PointD(polar_a_4.X + rectangle.Center.X, polar_a_4.Y + rectangle.Center.Y);

            return(new Tuple <PointD, PointD, PointD, PointD>(a1, a2, a3, a4));
        }