static void Main(String[] args) { string tempstr; Circle c1 = new Circle (); Circle c2 = new Circle (); Console.WriteLine("원충돌 테스트"); Console.WriteLine("circle1 X? "); tempstr = Console.ReadLine(); c1.x = Convert.ToInt32(tempstr); Console.WriteLine("circle1 Y? "); tempstr = Console.ReadLine(); c1.y = Convert.ToInt32(tempstr); Console.WriteLine("circle1 R? "); tempstr = Console.ReadLine(); c1.r = Convert.ToDouble(tempstr); Console.WriteLine("circle2 X?"); tempstr = Console.ReadLine(); c2.x = Convert.ToInt32(tempstr); Console.WriteLine("circle2 Y?"); tempstr = Console.ReadLine(); c2.y = Convert.ToInt32(tempstr); Console.WriteLine("circle2 R?"); tempstr = Console.ReadLine(); c2.r = Convert.ToDouble(tempstr); if ( (c1.x - c2.x)*(c1.x - c2.x) + (c1.y - c2.y)*(c1.y - c2.y) <= (c1.r + c2.r)*(c1.r + c2.r) ) Console.WriteLine(" 두 원은 충돌합니다."); else Console.WriteLine(" 두 원은 충돌하지 않습니다."); }
static void Main(String[] args) { Circle c1, c2; c1 = new Circle (); c2 = new Circle (); String tempstr; Console.WriteLine ("원충돌 테스트"); Console.Write ("circle1 x? "); tempstr = Console.ReadLine(); c1.x = Convert.ToInt32 (tempstr); Console.Write ("circle1 y? "); tempstr = Console.ReadLine (); c1.y = Convert.ToInt32 (tempstr); Console.Write ("circle1 r? "); tempstr = Console.ReadLine (); c1.r = Convert.ToDouble (tempstr); Console.Write ("circle2 x? "); tempstr = Console.ReadLine (); c2.x = Convert.ToInt32 (tempstr); Console.Write ("circle2 y? "); tempstr = Console.ReadLine (); c2.y = Convert.ToInt32 (tempstr); Console.Write ("circle2 r? "); tempstr = Console.ReadLine (); c2.r = Convert.ToDouble (tempstr); if (Math.Pow (c1.x-c2.x, 2) + Math.Pow(c1.y-c2.y, 2) <= Math.Pow(c1.r+c2.r, 2)) Console.WriteLine ("두 원은 충돌합니다."); else Console.WriteLine ("두 원은 충돌하지 않습니다."); }
static void Main(String[] args) { Circle c1, c2; string tempstr; // initiallize c1 & c2 c1 = new Circle (); c2 = new Circle (); // implement Console.WriteLine ("Cirlce Test"); Console.Write ("Circle1 X? "); tempstr = Console.ReadLine (); c1.x = Convert.ToInt32 (tempstr); Console.Write ("Circle1 Y? "); tempstr = Console.ReadLine (); c1.y = Convert.ToInt32 (tempstr); Console.Write ("Circle1 R? "); tempstr = Console.ReadLine (); c1.r = Convert.ToDouble (tempstr); Console.Write ("Circle2 X? "); tempstr = Console.ReadLine (); c2.x = Convert.ToInt32 (tempstr); Console.Write ("Circle2 Y? "); tempstr = Console.ReadLine (); c2.y = Convert.ToInt32 (tempstr); Console.Write ("Circle2 R? "); tempstr = Console.ReadLine (); c2.r = Convert.ToDouble (tempstr); if (Math.Pow (Math.Pow (c1.x - c2.x, 2) + Math.Pow (c1.y - c2.y, 2), 0.5) <= (c1.r + c2.r)) Console.WriteLine ("Boom~!!!!"); else Console.WriteLine ("Don't Worry"); }
static void Main(String[] args) { Circle c1, c2; String tempstr; Boolean result; int x; int y; int r; Console.WriteLine ("원충돌 테스트"); Console.Write ("circle1 X?"); tempstr = Console.ReadLine (); x = Convert.ToInt32 (tempstr); Console.Write ("circle1 Y?"); tempstr = Console.ReadLine (); y = Convert.ToInt32 (tempstr); Console.Write ("circle1 R?"); tempstr = Console.ReadLine (); r = Convert.ToInt32 (tempstr); c1 = new Circle (x, y, r); Console.Write ("circle2 X?"); tempstr = Console.ReadLine (); x = Convert.ToInt32 (tempstr); Console.Write ("circle2 Y?"); tempstr = Console.ReadLine (); y = Convert.ToInt32 (tempstr); Console.Write ("circle2 R?"); tempstr = Console.ReadLine (); r = Convert.ToInt32 (tempstr); c2 = new Circle (x, y, r); result = ((c1.x - c2.x) * (c1.x - c2.x) + (c1.y - c2.y) * (c1.y - c2.y)) > ((c1.r + c2.r) * (c1.r + c2.r)); //Console.Write (result); if (!result) Console.WriteLine ("두 원은 충돌합니다."); else Console.WriteLine ("두 원은 충돌하지 않습니다."); }