Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
2.0 kB
6
Indexable
Never
import java.util.ArrayList;
import java.util.List;

public class CircleRelationship {

    public static List<String> circleRelationship(List<String> circlePairs) {
        List<String> results = new ArrayList<>();

        for (String pair : circlePairs) {
            String[] coordinates = pair.split(" ");
            int x_a = Integer.parseInt(coordinates[0]);
            int y_a = Integer.parseInt(coordinates[1]);
            int r_a = Integer.parseInt(coordinates[2]);
            int x_b = Integer.parseInt(coordinates[3]);
            int y_b = Integer.parseInt(coordinates[4]);
            int r_b = Integer.parseInt(coordinates[5]);

            int distanceSquared = (x_a - x_b) * (x_a - x_b) + (y_a - y_b) * (y_a - y_b);
            int radiiSum = r_a + r_b;
            int radiiDiff = Math.abs(r_a - r_b);

            if (distanceSquared == 0) {
                if (radiiDiff == 0) {
                    results.add("Concentric");
                } else if (radiiDiff == radiiSum * radiiSum) {
                    results.add("Touching");
                } else if (radiiDiff > radiiSum * radiiSum) {
                    results.add("Disjoint-Inside");
                } else {
                    results.add("Intersecting");
                }
            } else if (distanceSquared == radiiSum * radiiSum || distanceSquared == radiiDiff * radiiDiff) {
                results.add("Touching");
            } else if (distanceSquared > radiiSum * radiiSum) {
                results.add("Disjoint-Outside");
            } else if (distanceSquared < radiiSum * radiiSum) {
                results.add("Intersecting");
            }
        }

        return results;
    }

    public static void main(String[] args) {
        List<String> circlePairs = List.of("12 0 21 14 0 23", "0 45 8 0 94 9", "35 8 13 10 0 38", "0 26 8 0 9 25");
        List<String> result = circleRelationship(circlePairs);
        System.out.println(result);
    }
}
Leave a Comment