Ejemplo n.º 1
0
        private void btnTestDraw_Click(object sender, EventArgs e)
        {
            Circle c1 = new Circle() { x = 400, y = 400, num = 1, r = 100 };
            Circle c2 = new Circle() { x = 400, y = 400, num = 2, r = 80, previous = c1, angleWithPrevious = Math.PI };
            c1.next.Add(c2);
            circles = new List<Circle>() { c1, c2 };

            Circle previous = c1;
            Circle current = c2;

            previous = current.previous;
            //Console.WriteLine("Circle " + current.num + " angle = " + current.angleWithPrevious);
            current.x = previous.x + (previous.r + current.r) * Math.Cos(current.angleWithPrevious);
            current.y = previous.y + (previous.r + current.r) * Math.Sin(current.angleWithPrevious);

            Draw(g);
        }
Ejemplo n.º 2
0
        private void draw_circle(int radius)
        {
            double angle = 0.0;
            double angle_stepsize = 0.3;

            // go through all angles from 0 to 2 * PI radians
            while (angle < 2 * Math.PI)
            {
                Circle c = new Circle();
                Canvas.SetLeft(c, radius * Math.Cos(angle) + 400);
                Canvas.SetTop(c, radius * Math.Sin(angle) + 50);
                c.X = Canvas.GetLeft(c);
                c.Y = Canvas.GetTop(c);
                c.angle = angle;
                canvas1.Children.Add(c);
                angle += angle_stepsize;
                lCircles.Add(c);
            }
        }
Ejemplo n.º 3
0
        private double CheckCollison(Circle c1, Circle c2)
        {
            double result = 0;

            double deltaX = Math.Abs(c1.x - c2.x);
            double deltaY = Math.Abs(c1.y - c2.y);
            double dist = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);

            double minDist = c1.r + c2.r;
            result = (1.1 * minDist - dist) / (0.8 * minDist);
            if (result < 0.0) result = 0.0;
            if (result > 1.0) result = 1.0;

            if (result == 0)
            {
                if (c1.collisions.ContainsKey(c2))
                {
                    c1.collisions.Remove(c2);
                    c1.amplifyVelocityCount = 2;
                }
                if (c2.collisions.ContainsKey(c1))
                {
                    c2.amplifyVelocityCount = 2;
                    c2.collisions.Remove(c1);
                }
            }
            else
            {
                if (c1.collisions.ContainsKey(c2)) c1.collisions[c2] = result; else c1.collisions.Add(c2, result);
                if (c2.collisions.ContainsKey(c1)) c2.collisions[c1] = result; else c2.collisions.Add(c1, result);
            }

            return result;
        }
Ejemplo n.º 4
0
        public double GetAngleBetweenCircles(Circle c1, Circle c2)
        {
            //
            //		c1 (fils)
            //		+
            //		 \
            //		  \
            //		   \
            //			+------------+ Origine
            //			c2 (parent)
            //
            double cos = c2.x - c1.x;
            double sin = c2.y - c1.y;
            double angle = Math.Acos(cos / Math.Sqrt(Math.Pow(cos, 2) + Math.Pow(sin, 2)));
            if (sin < 0) angle = Math.PI * 2 - angle;

            return angle;
        }