/* Dressed Gem */ import java.awt.*; public class D_Gem { public int x, y, radius, shield; public D_Gem() {} public void dress (int x, int y, int radius, int rover_width, int rover_height) { this.x = x; this.y = y; this.radius = radius; this.shield = Math.min(rover_width,rover_height)/2-1; } public boolean contains(int xx, int yy) { return ((xx-x)*(xx-x)+(yy-y)*(yy-y)<=radius*radius); } public boolean contains_segment(int xx1, int yy1, int xx2, int yy2) { // test if a straight line segment touch the circle double x1 = xx1 - x; double y1 = yy1 - y; double x2 = xx2 - x; double y2 = yy2 - y; double dx = x2 - x1; double dy = y2 - y1; // extend ray from x1 to x2 by alpha*(x2-x1), // test if alpha is between 0 and 1 if it cross with circle. // has to solve a quadratic equation. double a = dx*dx + dy*dy; double b = 2*(x1*dx + y1*dy); double c = x1*x1+y1*y1-radius*radius; double quotient = b*b-4*a*c; // the ray won't touch the circle if (quotient < 0) return false; // two roots double beta1 = (-b-Math.sqrt(quotient))/a/2.; double beta2 = (-b+Math.sqrt(quotient))/a/2.; return ( ((1 >= beta1) && (1 <= beta2)) || ((0 >= beta1) && (0 <= beta2)) || ((beta1 >= 0) && (beta1 <= 1)) || ((beta2 >= 0) && (beta2 <= 1)) ); } public boolean contains_poly(Polygon poly) { int i; boolean touch = false; for (i=0;(i