屏幕坐标系获取两个矩形面积及重叠面积,重叠面积比率的java代码
来源:互联网 发布:tcss.ping.https.js 编辑:程序博客网 时间:2024/05/15 19:14
import java.math.*;/** x,y为矩形左上角坐标,width为宽,height为高**/public class MyRectangle{public int x;public int y;public int width;public int height;public MyRectangle(){}public MyRectangle(int x,int y,int width,int height){this.x = x;this.y = y;this.width = width;this.height = height;}public int getArea(){return this.height * this.width;}public static int getOverLappingArea(MyRectangle a,MyRectangle b){int overLappingArea = 0;int startX = Math.min(a.x,b.x);int endX = Math.max(a.x + a.width, b.x + b.width);int overLappingWidth = a.width + b.width - (endX - startX);int startY = Math.min(a.y, b.y);int endY = Math.max(a.y + a.height, b.y + b.height);int overLappingHeight = a.height + b.height - (endY - startY);if(overLappingWidth <= 0 || overLappingHeight <= 0){overLappingArea = 0;}else{overLappingArea = overLappingWidth * overLappingHeight;}return overLappingArea;}public static double getOverLappingRate(MyRectangle a,MyRectangle b){double overLappingRate = 0.0;int overLappingArea = getOverLappingArea(a,b);if(overLappingArea == 0){overLappingRate = 0.0;}else{int areaA = a.getArea();int areaB = b.getArea();overLappingRate = (double)overLappingArea / (double)(areaA + areaB - overLappingArea);}return overLappingRate;}}
0 0
- 屏幕坐标系获取两个矩形面积及重叠面积,重叠面积比率的java代码
- 计算 矩形重叠面积
- HDU2056 矩形重叠面积
- 计算两个矩形重叠面积的简单方法
- HDU 2056 矩形重叠面积
- matlab之俩矩形框的重叠面积及重叠率
- hdu2056 矩形重叠面积(水题)
- hdoj2056(Rectangles 求矩形重叠面积
- 杭电acm2056 矩形重叠面积
- UVA 11345 Rectangles(n个矩形重叠覆盖的面积)
- D重叠面积
- 1504:重叠面积
- hdu 1255 覆盖的面积 矩形D层以上重叠面积
- uva11983 - Weird Advertisement 矩形面积并 重叠大于等于K次的面积
- 检测两个三角形是否有重叠面积/相交的方法
- 重叠面积--扫描线 hdu1255 覆盖的面积
- hdoj 1255 覆盖的面积【线段树 + 扫描线求重叠两次及以上的面积】
- ZZULIOJ 1816: 矩形 【矩形重叠面积的计算(区分相离与相交)】
- postgre数据库在上一个语句执行失败后,需要提交事务才能开始下一个语句
- oracle死锁,从查询,记录,到杀掉
- 使用JHipster创建一个应用 -JHipster学习(二)
- Creator关于坐标的一些代码
- 结构体Struct(c#)
- 屏幕坐标系获取两个矩形面积及重叠面积,重叠面积比率的java代码
- docker学习笔记---给容器分配局域网IP
- linux系统下修改.img系统内部文件
- UVA - 253 Cube painting
- 从生活角度学习应用程序、虚拟目录、应用程序池
- RAM和ROM容量计算
- pthread问题
- UVA - 621 Secret Research
- WebLogic+OSB(Oracle Server Bus)安装流程