Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CheckPointInCircle1
- (
- class CheckPointInCircle1
- {
- static void Main()
- {
- //(x-a)^2 + (y-b)^2 = r^2
- //x^2 == x*x
- //We need first part to be equal or small than the second,
- //becouse we looking for a point IN the circle.
- //The points on the perimeter of the circle ARE in it!
- double radiusR = 5;
- double circleX = 0;
- double circleY = 0;
- Console.WriteLine(@"Checking if given point (x, y) is within a circle K(O, 5)...");
- Console.Write(@"Please Provide ""x"": ");
- double pointX = double.Parse(Console.ReadLine());
- Console.Write(@"Please Provide ""y"": ");
- double pointY = double.Parse(Console.ReadLine());
- double checkX = (pointX - circleX) * (pointX - circleX); //(x-a)^2
- double checkY = (pointY - circleY) * (pointY - circleY); //(y-b)^2
- double xyCheck = (checkX + checkY); //(x-a)^2 + (y-b)^2
- double rCheck = (radiusR * radiusR); //r^2
- if (xyCheck <= rCheck)
- {
- Console.WriteLine("The pоint IS in the circle!");
- }
- else
- {
- Console.WriteLine("The point IS NOT in the circle!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement