-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold just polygon polyline.html
92 lines (73 loc) · 2.6 KB
/
old just polygon polyline.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<html>
<head>
<title>Point in Polygon Checker</title>
</head>
<body>
<h1>Point in Polygon Checker</h1>
<p>Enter Polygon Lat/Lng (One vertex per line):</p>
<textarea id="polygonCoords" rows="5" cols="40">28.418636,77.1620679
28.4138002,77.1601589
28.4097236,77.1600302
28.4070813,77.1622618
28.4066283,77.1666821</textarea>
<p>Enter Polyline Lat/Lng (One or more lines):</p>
<textarea id="polylineCoords" rows="5" cols="40">28.415,77.165
28.412,77.168
28.410,77.172
28.408,77.175</textarea>
<button onclick="checkPoints()">Check Points</button>
<h2>Results:</h2>
<table id="resultsTable">
<tr>
<th>Point</th>
<th>Inside Polygon</th>
</tr>
</table>
<script>
function isPointInsidePolygon(point, polygon) {
const x = point[0];
const y = point[1];
let isInside = false;
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
const xi = polygon[i][0];
const yi = polygon[i][1];
const xj = polygon[j][0];
const yj = polygon[j][1];
const intersect = ((yi > y) !== (yj > y)) &&
(x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect) {
isInside = !isInside;
}
}
return isInside;
}
function checkPoints() {
const polygonInput = document.getElementById("polygonCoords").value;
const polylineInput = document.getElementById("polylineCoords").value;
const polygonLines = polygonInput.split('\n').map(line => line.trim());
const polygon = polygonLines.map(line => line.split(',').map(parseFloat));
const polylineLines = polylineInput.split('\n').map(line => line.trim());
const polyline = polylineLines.map(line => line.split(',').map(parseFloat));
const resultsTable = document.getElementById("resultsTable");
resultsTable.innerHTML = `
<tr>
<th>Point</th>
<th>Inside Polygon</th>
</tr>
`;
for (let i = 0; i < polyline.length; i++) {
const point = polyline[i];
const isInside = isPointInsidePolygon(point, polygon);
const row = document.createElement("tr");
const pointCell = document.createElement("td");
const insideCell = document.createElement("td");
pointCell.textContent = `(${point[0]}, ${point[1]})`;
insideCell.textContent = isInside ? "Yes" : "No";
row.appendChild(pointCell);
row.appendChild(insideCell);
resultsTable.appendChild(row);
}
}
</script>
</body>
</html>