




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
import java.util.ArrayList;import java.util.List;/* * * * 2012-5-25下午4:37:31 */public class SystemTaskJob double INFINITY = 1e10; double ESP = 1e-5; int MAX_N = 1000;List Polygon;/ 计算叉乘 |P0P1| |P0P2|double Multiply(Point p1, Point p2, Point p0) return ( (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) );/ 判断线段是否包含点pointprivate boolean IsOnline(Point point, LineSegment line) return( ( Math.abs(Multiply(line.pt1, line.pt2, point) ESP ) & ( ( point.x - line.pt1.x ) * ( point.x - line.pt2.x ) = 0 ) & ( ( point.y - line.pt1.y ) * ( point.y - line.pt2.y ) = Math.min(L2.pt1.x, L2.pt2.x) & (Math.max(L2.pt1.x, L2.pt2.x) = Math.min(L1.pt1.x, L1.pt2.x) & (Math.max(L1.pt1.y, L1.pt2.y) = Math.min(L2.pt1.y, L2.pt2.y) & (Math.max(L2.pt1.y, L2.pt2.y) = Math.min(L1.pt1.y, L1.pt2.y) & (Multiply(L2.pt1, L1.pt2, L1.pt1) * Multiply(L1.pt2, L2.pt2, L1.pt1) = 0) & (Multiply(L1.pt1, L2.pt2, L2.pt1) * Multiply(L2.pt2, L1.pt2, L2.pt1) = 0) );/* 射线法判断点q与多边形polygon的位置关系,要求polygon为简单多边形,顶点逆时针排列如果点在多边形内: 返回0如果点在多边形边上: 返回1如果点在多边形外: 返回2*/public int InPolygon(List polygon, Point point)int n = polygon.size(); int count = 0; LineSegment line = new LineSegment(); line.pt1 = point; line.pt2.y = point.y; line.pt2.x = - INFINITY; for( int i = 0; i n; i+ ) / 得到多边形的一条边 LineSegment side = new LineSegment(); side.pt1 = polygon.get(i); side.pt2 = polygon.get(i + 1) % n); if( IsOnline(point, side) ) return 1 ; / 如果side平行x轴则不作考虑 if( Math.abs(side.pt1.y - side.pt2.y) side.pt2.y ) count+; else if( IsOnline(side.pt2, line) ) if( side.pt2.y side.pt1.y ) count+; else if( Intersect(line, side) ) count+; if ( count % 2 = 1 ) return 0; else return 2; public static void main(String args) SystemTaskJob systemTaskJob = new SystemTaskJob(); List polygon = new ArrayList(); Point point1 = new Point(4,9); Point point2 = new Point(7,10); Point point3 = new Point(8,2); Point point4 = new Point(6,8); Point point5 = new Point(6,9); Point checkpoint = new Point(7,11); polygon.add(point1); polygon.add(point2); polygon.add(point3); polygon.add(point4); polygon.add(point5); int m = systemTaskJob.InPolygon(polygon, checkpoint); System.out.println(=+m); class Point public double x; public double y; public Point() public Point(double x,double y) this.x=x; this.y=y; class
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 遗传咨询师模拟考试题及答案
- 驾校科三灯光考试题库及答案
- 6年级下册的考试卷子及答案
- 山东省中职春考试题库及答案
- 机电一体化知识考试题及答案
- 《人格心理学》试题及详细答案
- 孕产服务区域差异研究-洞察与解读
- 变电站故障动态分析方法-洞察与解读
- 2025年济南市事业单位招聘考试综合类专业能力测试试卷(旅游类)案例分析真题模拟解析
- 2025年事业单位招聘考试教师地理学科专业知识试卷及答案
- 2025年材料员考试题库及完整答案(历年真题)
- 品质测量基础知识培训课件
- 2025四川绵阳市粮油集团有限公司招聘财务管理等岗位5人笔试题库历年考点版附带答案详解
- 2025年《长征》试题及答案
- 企业财务制度规范范本合集
- 钢结构施工方案样本
- Unit4WonderfulseasonsGetreadyandstartup(课件)-外研版英语四年级上册
- 新闻记者职业资格《新闻采编实务》考试题库(含答案)
- 【高等数学练习题】沈阳大学专升本自考真题汇总(附答案解析)
- 合作项目管理办法
- 建设项目安全设施“三同时”检查表
评论
0/150
提交评论