Exemplo n.º 1
0
        //Tìm 1 điểm có thuộc trong một vât thể hay không
        public bool tim(clsDrawObj obj, Point p)
        {
            if (obj.loai == 1)
            {
                // diem click thuoc duong thang
                int a = Convert.ToInt32(Math.Sqrt((obj.p1.X - p.X) * (obj.p1.X - p.X) + (obj.p1.Y - p.Y) * (obj.p1.Y - p.Y)));
                int b = Convert.ToInt32(Math.Sqrt((obj.p2.X - p.X) * (obj.p2.X - p.X) + (obj.p2.Y - p.Y) * (obj.p2.Y - p.Y)));
                int c = Convert.ToInt32(Math.Sqrt((obj.p1.X - obj.p2.X) * (obj.p1.X - obj.p2.X) + (obj.p1.Y - obj.p2.Y) * (obj.p1.Y - obj.p2.Y)));

                if (a + b == c)
                {
                    return(true);
                }
            }
            if (obj.loai == 2)
            {
                //diem click thuoc hinh chu nhat
                if (obj.p1.X < p.X && obj.p2.X > p.X && obj.p1.Y < p.Y && obj.p2.Y > p.Y || obj.p1.X > p.X && obj.p2.X < p.X && obj.p1.Y > p.Y && obj.p2.Y < p.Y)
                {
                    return(true);
                }
            }
            if (obj.loai == 3)
            {
                if (obj.p1.X < p.X && obj.p2.X > p.X && obj.p1.Y < p.Y && obj.p2.Y > p.Y || obj.p1.X > p.X && obj.p2.X < p.X && obj.p1.Y > p.Y && obj.p2.Y < p.Y)
                {
                    return(true);
                }
            }
            if (obj.loai == 4)
            {
                //khoang cach tu diem den ban kinh
                //Để tính tâm thì bạn lấy x1 = (chiều dài / 2) +x, y1 = (chiều rộng / 2) +y. => O(x1, y1).
                double r = Math.Abs((obj.p1.X - obj.p2.X) / 2);
                //toa do tam
                double x1 = r + obj.p1.X;
                double x2 = r + obj.p1.Y;
                //do dai tu diem a den ban kinh
                double a = Math.Abs(Math.Sqrt((x1 - p.X) * (x1 - p.X) + (x2 - p.Y) * (x2 - p.Y)));

                if (a < r)
                {
                    return(true);
                }
            }
            if (obj.loai == 7)
            {
                //ban kinh lon nho
                double r1 = Math.Abs(obj.p1.X - obj.p2.X);
                double r2 = Math.Abs(obj.p1.Y - obj.p2.Y);
                if (p.X >= obj.p1.X && p.Y >= obj.p1.Y && p.X <= obj.p1.X + r1 && p.Y <= obj.p1.Y + r2)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
 private void btel_Click(object sender, EventArgs e)
 {
     draw    = 7;
     isPress = true;
     myObj   = new clsElips();
 }
Exemplo n.º 3
0
 private void btcir_Click(object sender, EventArgs e)
 {
     draw    = 4;
     myObj   = new clsCir();
     isPress = true;
 }
Exemplo n.º 4
0
 private void btsqr_Click(object sender, EventArgs e)
 {
     draw    = 3;
     myObj   = new clsSqr();
     isPress = true;
 }
Exemplo n.º 5
0
 private void btrect_Click(object sender, EventArgs e)
 {
     draw    = 2;
     myObj   = new clsRect();
     isPress = true;
 }
Exemplo n.º 6
0
 private void btline_Click(object sender, EventArgs e)
 {
     draw    = 1;
     myObj   = new clsLine();
     isPress = true;
 }