-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
427 lines (344 loc) · 16.4 KB
/
Copy pathscript.js
File metadata and controls
427 lines (344 loc) · 16.4 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
const x1=document.getElementById("myknownX1")
const y1=document.getElementById("myknownY1")
const x2=document.getElementById("myknownX2")
const y2=document.getElementById("myknownY2")
const bearingbutton = document.getElementById("bearing")
const bearingresult= document.getElementById("bearingresult")
const nAngle=document.getElementById("myinputnumber1")
const nresult=document.getElementById("nresult")
const submitbutton = document.getElementById("submitbutton1")
const inputboxAngles=document.getElementById("inputboxAngles")
function getBearing() {
const x1Value = parseFloat(x1.value);
const y1Value = parseFloat(y1.value);
const x2Value = parseFloat(x2.value);
const y2Value = parseFloat(y2.value);
if (isNaN(x1Value) || isNaN(y1Value) || isNaN(x2Value) || isNaN(y2Value)) {
bearingresult.textContent = "Please enter valid coordinates for both stations.";
return;
}
const dx = x2Value - x1Value;
const dy = y2Value - y1Value;
let bearing = Math.atan2(dx, dy) * (180 / Math.PI);
if (bearing < 0) {
bearing += 360;
}
bearingresult.textContent = `The bearing of line is:${bearing.toFixed(2)}°`;
}
bearingbutton.addEventListener('click', getBearing);
function newFunction(bearing) {
bearing.innerHTML += "<br>"
}
function getnAngles()
{
const numberofAngles=parseInt(nAngle.value,10);
nresult.innerhtml='<br>';
nresult.textContent="!!!!!Enter each Angles in decimal degrees!!!!";
inputboxAngles.innerHTML="";
if(isNaN(numberofAngles)|| numberofAngles<=0)
{
nresult.textContent="Please enter a valid number greater than 0."
return;
}
else if(numberofAngles<3)
{
nresult.textContent="A minimum of three angles is required for a closed traverse."
return;
}
for(let i=0; i<numberofAngles; i++)
{
const inputBox=document.createElement("input");
inputBox.type="number";
inputBox.placeholder="Enter Angle"+(i+1)+":";
inputBox.className="angleInputBox"
inputboxAngles.appendChild(inputBox);
}
if (!document.getElementById('calculateButton'))
{
const calculateButton = document.createElement('button');
calculateButton.textContent = 'CalculateClosingError';
calculateButton.id = 'calculateButton';
inputboxAngles.appendChild(calculateButton);
calculateButton.addEventListener('click', storeAngle);
}
}
function storeAngle()
{
const inputBoxes = document.querySelectorAll('.angleInputBox');
var angles = [];
for (let i = 0; i < inputBoxes.length; i++) {
const inputBoxx = inputBoxes[i];
const angleValue = parseFloat(inputBoxx.value);
if (!isNaN(angleValue)) {
angles.push(angleValue);
} else {
alert('Please enter a valid number for Angle ' + (i + 1) + ":");
return;
}
}
var observedAngle = 0
for (let i = 0; i < angles.length; i++) {
observedAngle += angles[i];
}
const actualAngle = (angles.length - 2) * 180;
const Correction = actualAngle - observedAngle;
var disCorrection = Correction / angles.length;
inputboxAngles.innerHTML += "<br>";
inputboxAngles.innerHTML += "<br>";
inputboxAngles.innerHTML += "Total Observed Angle Sum: " + observedAngle.toFixed(2) + "°";
inputboxAngles.innerHTML += "<br>";
inputboxAngles.innerHTML += "Total Actual Angle Sum: " + actualAngle.toFixed(2) + "°";
inputboxAngles.innerHTML += "<br>";
inputboxAngles.innerHTML += "Error: " + Correction.toFixed(2) + "°";
inputboxAngles.innerHTML += "<br>";
inputboxAngles.innerHTML += "<br>";
inputboxAngles.innerHTML += '<strong>Corrected Angles:</strong>';
inputboxAngles.innerHTML += "<br>";
for (let i = 0; i < angles.length; i++) {
const correctedAngle = angles[i] + disCorrection;
const correctedInputBox = document.createElement("input");
correctedInputBox.type = "text";
correctedInputBox.value = 'Angle' +(i + 1)+":"+ correctedAngle.toFixed(3)+"°";
correctedInputBox.disabled = true;
correctedInputBox.className = "correctedAngleBox";
inputboxAngles.appendChild(correctedInputBox);
inputboxAngles.appendChild(document.createElement("br"));
}
// Button to Calculate Bearings
const calculateBearingsButton = document.createElement('button');
calculateBearingsButton.textContent = 'Calculate Bearings';
calculateBearingsButton.id = 'calculateBearingsButton';
inputboxAngles.appendChild(calculateBearingsButton);
calculateBearingsButton.addEventListener('click', calculateBearings);
}
function calculateBearings() {
const correctedAngles = document.querySelectorAll('.correctedAngleBox');
const initialBearing = parseFloat(bearingresult.textContent.split(":")[1]);
let currentBearing = initialBearing;
const bearingsContainer = document.createElement('div');
bearingsContainer.id = 'bearingsContainer';
inputboxAngles.appendChild(bearingsContainer);
bearingsContainer.innerHTML += '<strong>Calculated Bearings:</strong><br>';
const initialBearingBox = document.createElement("input");
initialBearingBox.type = "text";
initialBearingBox.value = 'Bearing 1:'+ currentBearing.toFixed(2)+"°";
initialBearingBox.disabled = true;
initialBearingBox.className = "bearingBox";
bearingsContainer.appendChild(initialBearingBox);
bearingsContainer.appendChild(document.createElement("br"));
for (let i = 0; i < correctedAngles.length; i++) {
const angleValue = parseFloat(correctedAngles[i].value.split(":")[1]);
currentBearing = calculateNewBearing(currentBearing, angleValue);
const bearingInputBox = document.createElement("input");
bearingInputBox.type = "text";
bearingInputBox.value = "Bearing" +(i+2)+ ":"+ currentBearing.toFixed(2)+"°";
bearingInputBox.disabled = true;
bearingInputBox.className = "bearingBox";
bearingsContainer.appendChild(bearingInputBox);
bearingsContainer.appendChild(document.createElement("br"));
}
// Button to Enter Distance
const enterdistanceButton = document.createElement('button');
enterdistanceButton.textContent = 'Enter Distance';
enterdistanceButton.id = 'enterdistanceButton';
inputboxAngles.appendChild(enterdistanceButton);
enterdistanceButton.addEventListener('click', enterDistance);
}
function calculateNewBearing(previousBearing, includedAngle) {
if(previousBearing<180)
{
let newBearing = previousBearing + 180+includedAngle;
if (newBearing >= 360) {
newBearing -=360;}
else if (newBearing < 0) {
newBearing+= 360;}
return newBearing;
}
else
{
let newBearing = previousBearing - 180+ includedAngle;
if (newBearing >= 360) {
newBearing -= 360;}
else if (newBearing < 0) {
newBearing += 360;}
return newBearing;
}
}
function enterDistance()
{
const bearingBoxes = document.querySelectorAll('.bearingBox');
const oldDistancesContainer = document.getElementById('distancesContainer');
if (oldDistancesContainer) {
oldDistancesContainer.remove();
}
const distancesContainer = document.createElement('div');
distancesContainer.id = 'distancesContainer';
inputboxAngles.appendChild(distancesContainer);
distancesContainer.innerHTML += '<strong>Enter Distances:</strong><br>';
for (let i = 1; i < bearingBoxes.length; i++) {
const distanceInputBox = document.createElement("input");
distanceInputBox.type = "number";
distanceInputBox.placeholder = "Distance"+ i;
distanceInputBox.className = "distanceInputBox";
distancesContainer.appendChild(distanceInputBox);
distancesContainer.appendChild(document.createElement("br"));
}
// Button to Calculate Latitude and Departure
const calculateLatDepButton = document.createElement('button');
calculateLatDepButton.textContent = 'Calculate Latitude and Departure';
calculateLatDepButton.id = 'calculateLatDepButton';
distancesContainer.appendChild(calculateLatDepButton);
calculateLatDepButton.addEventListener('click', calculateLatitudeDeparture);
}
function calculateLatitudeDeparture() {
const bearingBoxes = document.querySelectorAll('.bearingBox');
const distanceInputs = document.querySelectorAll('.distanceInputBox');
const oldResultsContainer = document.getElementById('resultsContainer');
if (oldResultsContainer) {
oldResultsContainer.remove();
}
const resultsContainer = document.createElement('div');
resultsContainer.id = 'resultsContainer';
inputboxAngles.appendChild(resultsContainer);
let totalLatitude = 0;
let totalDeparture = 0;
let perimeter = 0;
window.lines = [];
resultsContainer.innerHTML += '<strong>Calculated Latitude and Departure:</strong><br>';
for (let i = 0; i < distanceInputs.length; i++) {
const bearing = parseFloat(bearingBoxes[i + 1].value.split(":")[1]);
const distance = parseFloat(distanceInputs[i].value);
if (isNaN(distance) || isNaN(bearing)) {
alert("Please enter a valid distance and bearing for line"+ (i + 1));
return;
}
const latitude = distance * Math.cos(bearing * Math.PI / 180);
const departure = distance * Math.sin(bearing * Math.PI / 180);
totalLatitude += latitude;
totalDeparture += departure;
perimeter += distance;
window.lines.push({distance, latitude, departure});
const resultBox = document.createElement("input");
resultBox.type = "text";
resultBox.value = "Line" +(i + 1)+":" +"Lat="+latitude.toFixed(4)+","+ "Dep=" +departure.toFixed(4);
resultBox.disabled = true;
resultBox.className = "latDepBox";
resultsContainer.appendChild(resultBox);
resultsContainer.appendChild(document.createElement("br"));
}
const totalBox = document.createElement("input");
totalBox.type = "text";
totalBox.value = "Total:" +"Lat=" +totalLatitude.toFixed(4)+","+ "Dep=" +totalDeparture.toFixed(4);
totalBox.disabled = true;
totalBox.className = "latDepBox";
resultsContainer.appendChild(totalBox);
resultsContainer.appendChild(document.createElement("br"));
// Adding button for Bowditch correction
const correctButton = document.createElement('button');
correctButton.textContent = 'Apply Bowditch Correction';
correctButton.id = 'correctLatDepButton';
resultsContainer.appendChild(correctButton);
correctButton.addEventListener('click', applyBowditchCorrection);
}
function applyBowditchCorrection() {
const resultsContainer = document.getElementById('resultsContainer');
const existingContent = resultsContainer.innerHTML;
// Calculate totals again
let totalLatitude = 0;
let totalDeparture = 0;
let perimeter = 0;
for (const line of window.lines) {
totalLatitude += line.latitude;
totalDeparture += line.departure;
perimeter += line.distance;
}
resultsContainer.insertAdjacentHTML('beforeend', '<br><strong>Corrected Latitude and Departure:</strong><br>');
let correctedTotalLat = 0;
let correctedTotalDep = 0;
for (let i = 0; i < window.lines.length; i++) {
const line = window.lines[i];
const latCorrection = (totalLatitude * line.distance) / perimeter;
const depCorrection = (totalDeparture * line.distance) / perimeter;
const correctedLat = line.latitude - latCorrection;
const correctedDep = line.departure - depCorrection;
correctedTotalLat += correctedLat;
correctedTotalDep += correctedDep;
const correctedBox = document.createElement("input");
correctedBox.type = "text";
correctedBox.value = "Line" +(i + 1)+":" +"Lat=" +correctedLat.toFixed(4)+","+ "Dep=" +correctedDep.toFixed(4);
correctedBox.disabled = true;
correctedBox.className = "correctedLatDepBox";
resultsContainer.appendChild(correctedBox);
resultsContainer.appendChild(document.createElement("br"));
// Sotring corrected values in the lines array
window.lines[i].correctedLatitude = correctedLat;
window.lines[i].correctedDeparture = correctedDep;
}
const correctedTotalBox = document.createElement("input");
correctedTotalBox.type = "text";
correctedTotalBox.value = `Corrected Totals: Lat ${correctedTotalLat.toFixed(4)}, Dep ${correctedTotalDep.toFixed(4)}`;
correctedTotalBox.disabled = true;
correctedTotalBox.className = "correctedLatDepBox";
resultsContainer.appendChild(correctedTotalBox);
resultsContainer.appendChild(document.createElement("br"));
if (!document.getElementById('calculateCoordinatesButton')){
// Adding button to calculate coordinates
const calculateCoordinatesButton = document.createElement('button');
calculateCoordinatesButton.textContent = 'Calculate Coordinates';
calculateCoordinatesButton.id = 'calculateCoordinatesButton';
resultsContainer.appendChild(calculateCoordinatesButton);
calculateCoordinatesButton.addEventListener('click', calculateCoordinates);}
}
function calculateCoordinates(){
const resultsContainer = document.getElementById('resultsContainer');
const x1Value = parseFloat(document.getElementById("myknownX1").value);
const y1Value = parseFloat(document.getElementById("myknownY1").value);
if (isNaN(x1Value) || isNaN(y1Value)) {
alert("Please enter valid coordinates for the first known station.");
return;
}
resultsContainer.insertAdjacentHTML('beforeend', '<br><strong>Calculated Coordinates:</strong><br>');
let currentX = x1Value;
let currentY = y1Value;
const coordinateBox = document.createElement("input");
coordinateBox.type = "text";
coordinateBox.value = `Station 1: X ${currentX.toFixed(4)}, Y ${currentY.toFixed(4)}`;
coordinateBox.disabled = true;
coordinateBox.className = "coordinateBox";
resultsContainer.appendChild(coordinateBox);
resultsContainer.appendChild(document.createElement("br"));
for (let i = 0; i < window.lines.length; i++) {
const line = window.lines[i];
currentX += line.correctedDeparture;
currentY += line.correctedLatitude;
const coordinateBox = document.createElement("input");
coordinateBox.type = "text";
coordinateBox.value = `Station ${i + 2}: X ${currentX.toFixed(4)}, Y ${currentY.toFixed(4)}`;
coordinateBox.disabled = true;
coordinateBox.className = "coordinateBox";
resultsContainer.appendChild(coordinateBox);
resultsContainer.appendChild(document.createElement("br"));
}
if (!document.getElementById('calculateMisclosureButton')) {
const misclosureButton = document.createElement('button');
misclosureButton.textContent = 'Show Misclosure and Linear Accuracy';
misclosureButton.id = 'calculateMisclosureButton';
resultsContainer.appendChild(misclosureButton);
misclosureButton.addEventListener('click', calculateMisclosureAndAccuracy);}
}
function calculateMisclosureAndAccuracy() {
const resultsContainer = document.getElementById('resultsContainer');
let uncorrectedTotalLat = 0;
let uncorrectedTotalDep = 0;
let perimeter = 0;
for (const line of window.lines) {
uncorrectedTotalLat += line.latitude;
uncorrectedTotalDep += line.departure;
perimeter += line.distance;
}
const misclosure = Math.sqrt(Math.pow(uncorrectedTotalLat, 2) + Math.pow(uncorrectedTotalDep, 2));
const linearAccuracy = perimeter / misclosure;
resultsContainer.insertAdjacentHTML('beforeend', `<br><strong>Misclosure: </strong>${misclosure.toFixed(4)} units<br>`);
resultsContainer.insertAdjacentHTML('beforeend', `<strong>Linear Accuracy: </strong>${linearAccuracy.toFixed(4)} (Perimeter / Misclosure)<br>`);
}
submitbutton.addEventListener('click', getnAngles);