Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class Point {
- private int x;
- private int y;
- public Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
- public int getX() {
- return x;
- }
- public void setX(int x) {
- this.x = x;
- }
- public int getY() {
- return y;
- }
- public void setY(int y) {
- this.y = y;
- }
- }
- public class Circle {
- private Point center;
- private int radius;
- public Circle(Point center, int radius) {
- this.center = center;
- this.radius = radius;
- }
- public Point getCenter() {
- return center;
- }
- public void setCenter(Point center) {
- this.center = center;
- }
- public int getRadius() {
- return radius;
- }
- public void setRadius(int radius) {
- this.radius = radius;
- }
- }
- public class IntersectionOfCircles {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] cirleOneProps = Arrays.stream(scanner.nextLine().split("\\s"))
- .mapToInt(Integer::parseInt).toArray();
- int[] cirleTwoProps = Arrays.stream(scanner.nextLine().split("\\s"))
- .mapToInt(Integer::parseInt).toArray();
- Point centerOne = new Point(cirleOneProps[0],cirleOneProps[1]);
- Point centerTwo = new Point(cirleTwoProps[0],cirleTwoProps[1]);
- Circle circleOne = new Circle(centerOne,cirleOneProps[2]);
- Circle circleTwo = new Circle(centerTwo,cirleTwoProps[2]);
- double distance = CalculateDistance(centerOne, centerTwo);
- boolean areIntersect = Intersect(circleOne, circleTwo, distance);
- if (areIntersect){
- System.out.println("Yes");
- }else {
- System.out.println("No");
- }
- }
- public static boolean Intersect(Circle c1, Circle c2, double distance){
- boolean areIntersect = false;
- if (distance <= c1.getRadius() + c2.getRadius()){
- areIntersect = true;
- }
- return areIntersect;
- }
- public static double CalculateDistance(Point p1, Point p2){
- double differenceOfY = p1.getY() - p2.getY();
- double differenceOfX = p1.getX() - p2.getX();
- double powX = Math.pow(differenceOfX,2);
- double powY = Math.pow(differenceOfY,2);
- return Math.sqrt(powX+powY);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement