Skip to content

Commit 78b2363

Browse files
committed
GIS基本算法--01判断点是否在线上
1 parent 6a11494 commit 78b2363

File tree

7 files changed

+192
-0
lines changed

7 files changed

+192
-0
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GIS_algorithm.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

src/algo/PointOnLine.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package algo;
2+
3+
/**
4+
* @ClassName PointOnLine
5+
* @Description 判断点是否在线上
6+
* @Author luokai
7+
* @CreateDate 2020/8/15 22:51
8+
* @UPpdateUser luokai
9+
* @UpdateDate 2020/8/15 22:51
10+
* @UpdateRemark
11+
* @Version 1.0
12+
* Copyright (c) 2019,武汉中地云申科技有限公司
13+
* All rights reserved.
14+
**/
15+
16+
/**
17+
* 算法原理介绍
18+
* 判断一个点是否在一条线上,其原理是利用叉积乘。a×b=|x1, y1|=x1y2-x2y1
19+
* |x2, y2|
20+
* 例如点Q是否在线段p1和P2上 (Q-p1)✖(p2-p1) = 0
21+
* 除此之外,还要保证该点在点p1 p2所连成的对角矩阵的内部 因为第一个条件满足的情况下 可能是p1p2的延长线上
22+
*
23+
*
24+
*/
25+
26+
import entity.Point;
27+
28+
public class PointOnLine {
29+
30+
public boolean PointOnLine(Point p1, Point p2, Point q ){
31+
boolean flag = false; // true 点在线上 false 点不在线上
32+
33+
if(((q.getLon()-p1.getLon()) * (p2.getLat()-p1.getLat()) - (q.getLat()-p1.getLat()) * (p2.getLon()-p1.getLon())) == 0){
34+
//System.out.println("点在线上这条直线上");
35+
if(p1.getLon() >= p2.getLon() && p1.getLat() >= p2.getLat()){
36+
//点p1在点p2右上方 p1x > p2x p1y> p2y
37+
if(q.getLon() <= p1.getLon() && q.getLon() >= p2.getLon() && q.getLat() <= p1.getLat() && q.getLat() >= p2.getLat()){
38+
flag = true;
39+
}
40+
}else if(p1.getLon() >= p2.getLon() && p1.getLat() <= p2.getLat()){
41+
//点p1在点p2的右下方 p1x > p2x p1y < p2y
42+
if(q.getLon() <= p1.getLon() && q.getLon() >= p2.getLon() && q.getLat() >= p1.getLat() && q.getLat() <= p2.getLat()){
43+
flag = true;
44+
}
45+
}else if(p1.getLon() <= p2.getLon() && p1.getLat() >= p2.getLat()){
46+
//点p1在p2左上方 p1x < p2x p1y > p2y
47+
if(q.getLon() >= p1.getLon() && q.getLon() <= p2.getLon() && q.getLat() <= p1.getLat() && q.getLat() >= p2.getLat()){
48+
flag = true;
49+
}
50+
}else if(p1.getLon() <= p2.getLon() && p1.getLat() <= p2.getLat()){
51+
//点p1在p2左下方 p1x < p2x p1y < p2y
52+
if(q.getLon() >= p1.getLon() && q.getLon() <= p2.getLon() && q.getLat() >= p1.getLat() && q.getLat() <= p2.getLat()){
53+
flag = true;
54+
}
55+
}
56+
}
57+
return flag;
58+
}
59+
}

src/entity/Point.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package entity;
2+
3+
/**
4+
* @ClassName Point
5+
* @Description 定义坐标点
6+
* @Author luokai
7+
* @CreateDate 2020/8/15 22:52
8+
* @UPpdateUser luokai
9+
* @UpdateDate 2020/8/15 22:52
10+
* @UpdateRemark
11+
* @Version 1.0
12+
* Copyright (c) 2019,武汉中地云申科技有限公司
13+
* All rights reserved.
14+
**/
15+
public class Point {
16+
public Point(double lon, double lat) {
17+
this.lon = lon;
18+
this.lat = lat;
19+
}
20+
21+
//定义经纬度
22+
private double lon;
23+
private double lat;
24+
25+
public double getLon() {
26+
return lon;
27+
}
28+
29+
public void setLon(double lon) {
30+
this.lon = lon;
31+
}
32+
33+
public double getLat() {
34+
return lat;
35+
}
36+
37+
public void setLat(double lat) {
38+
this.lat = lat;
39+
}
40+
41+
}

src/test/Test01.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package test;
2+
3+
/**
4+
* @ClassName Test01
5+
* @Description TODO
6+
* @Author luokai
7+
* @CreateDate 2020/8/16 11:41
8+
* @UPpdateUser luokai
9+
* @UpdateDate 2020/8/16 11:41
10+
* @UpdateRemark
11+
* @Version 1.0
12+
* Copyright (c) 2019,武汉中地云申科技有限公司
13+
* All rights reserved.
14+
**/
15+
import entity.Point;
16+
import algo.PointOnLine;
17+
public class Test01 {
18+
public static void main(String args[]){
19+
Point p1 = new Point(110,30);
20+
Point p2 = new Point(115, 40);
21+
Point q = new Point(112, 34);
22+
23+
PointOnLine pointOnLine = new PointOnLine();
24+
boolean flag = pointOnLine.PointOnLine(p1, p2, q);
25+
if(flag){
26+
System.out.println("该点在线上");
27+
}else{
28+
System.out.println("该点不在线上");
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)