Untitled
unknown
java
8 months ago
1.7 kB
4
Indexable
Never
import java.util.ArrayList; import java.util.List; public class CircleRelationships { public static List<String> circles(List<String> circlePairs) { List<String> result = new ArrayList<>(); for (String pair : circlePairs) { // Parse the descriptors for circle A and circle B String[] parts = pair.split(" "); int xA = Integer.parseInt(parts[0]); int yA = Integer.parseInt(parts[1]); int rA = Integer.parseInt(parts[2]); int xB = Integer.parseInt(parts[3]); int yB = Integer.parseInt(parts[4]); int rB = Integer.parseInt(parts[5]); // Calculate the distance between the centers of the circles double distance = Math.sqrt(Math.pow(xA - xB, 2) + Math.pow(yA - yB, 2)); // Check the relationship between the circles based on their positions and sizes if (distance == rA + rB) { result.add("Touching"); } else if (distance == 0 && rA == rB) { result.add("Concentric"); } else if (distance < rA + rB) { result.add("Intersecting"); } else if (distance > rA + rB) { if (distance > Math.max(rA, rB)) { result.add("Disjoint-Outside"); } else { result.add("Disjoint-Inside"); } } } return result; } public static void main(String[] args) { List<String> circlePairs = new ArrayList<>(); // Add circle pairs to the list List<String> result = circles(circlePairs); System.out.println(result); } }
Leave a Comment