我在此真誠地混淆了自己......哪一個實際返回兩個矩形之間的交集區域?請認真解釋(數學挫敗我)。任何幫助,將不勝感激。獲取兩個相交矩形的面積
方法一: double newX = Math.max(this.x,rect2.x); double newY = Math.max(this.y,rect2.y); return new Rect(newX,newY,Math.min(this.x + this.width,rect2.x + rect2.width) - newX,Math.min(this.y + this.height,rect2.y + rect2 .height) - newY);
方法有兩個:
雙areaOfIntersection = Math.max(0,Math.max(rect1x2,rect2x2) - Math.min(rect1x1,rect2x1)) * Math.max(0,Math.max( rect1y2,rect2y2) - Math.min(rect1y1,rect2y1));
我覺得這個問題在這裏很合適http://math.stackexchange.com/ – 2013-03-08 17:05:37
這是一個數學問題還是一個編程問題? – pamphlet 2013-03-08 17:06:03