void DDA(Figure c1, Figure c2, Color color, int R, int parpadeo, PictureBox pb) { float r1 = c1.R + R / 2, r2 = c2.R + R / 2; int x1 = c1.X, y1 = c1.Y, x2 = c2.X, y2 = c2.Y; float ax, ay, x, y, res, i = 0, distanceLineActual; if (Math.Abs(x2 - x1) >= Math.Abs(y2 - y1)) { res = Math.Abs(x2 - x1); } else { res = Math.Abs(y2 - y1); } ax = (x2 - x1) / res; ay = (y2 - y1) / res; x = (float)x1; y = (float)y1; Graphics g = Graphics.FromImage(bmpBackGround); Brush b = new SolidBrush(color); while (i <= res) { distanceLineActual = c1.distance((int)x, (int)y); if (distanceLineActual > r1 && distanceLineActual < c1.distance(c2) - r2) { //este condicional impide el analizis dentro del area de los circulos //g.Clear(Color.Transparent); g.FillEllipse(b, x - (R / 2), y - (R / 2), R, R); } x += ax; y += ay; i++; //genera una simple aimacion if (i % parpadeo == 0) { pb.Refresh(); } } pb.Refresh(); }
List <Point> collisionDDA(Figure c1, Figure c2, Bitmap bmp_) { float r1 = c1.R + 5, r2 = c2.R + 5; int x1 = c1.X, y1 = c1.Y, x2 = c2.X, y2 = c2.Y; float ax, ay, x, y, res, i = 0, distanceLineActual; if (Math.Abs(x2 - x1) >= Math.Abs(y2 - y1)) { res = Math.Abs(x2 - x1); } else { res = Math.Abs(y2 - y1); } ax = (x2 - x1) / res; ay = (y2 - y1) / res; x = (float)x1; y = (float)y1; List <Point> points = new List <Point>(); while (i <= res) { distanceLineActual = c1.distance((int)x, (int)y); if (distanceLineActual > r1 && distanceLineActual < c1.distance(c2) - r2) { //este condicional impide el analizis dentro del area de los circulos //esto evitara notar colisiones con el mismo circulo if (collision((int)x, (int)y, bmp_)) { return(null); } if (collision((int)(x + ax), (int)y, bmp_)) { return(null); } } points.Add(new Point((int)x, (int)y)); x += ax; y += ay; i++; } return(points); }