i got a problem - when i update the "distanz" of my object "Punkt" it is not being changed, so how can i update the attributes of the object?
I also have the problem that i can't figure out how to delete the object that is 100% similar to "AE_punkt" - i would like to know how to remove it out of the array.
Thanks for all upcomming help!
function Punkt(name, x, y, check, distanz) {
this.name = name;
this.x = x; //Längengrad
this.y = y; //Breitengrad
this.check = check;
this.distanz = distanz;
}
function getDistanz(x1, y1, x2, y2) {
var y = 111.3 * (y1 - y2); //111.3 = Abstand zwischen zwei Breitenkreisen in km
var x = 71.5 * (x1 - x2); //71.5 = Abstand zwischen zwei Längenkreisen in km
return Math.sqrt((x * x) + (y * y));
}
function compare(a, b) {
if (a < b) {
return true;
}
}
function nearestNeighbour() {
var array = new Array();
// in Array automatisch einfügen
// Breiten- und Längengrad von https://www.laengengrad-breitengrad.de/
var Dresden = new Punkt("Dresden", 13.7372621, 51.0504088, false, 0);
array.push(Dresden);
var Muenchen = new Punkt("München", 11.581981, 48.135125, false, 0);
array.push(Muenchen);
var Berlin = new Punkt("Berlin", 13.404954, 52.520007, false, 0);
array.push(Berlin);
var AE_punkt = new Punkt("Berlin", 13.404954, 52.520007, false, 0);
//while schleife am besten
var min = 9999999999999999999999999999;
for (var i = 0; i < array.length; i++) {
array[i].distanz = this.getDistanz(AE_punkt.x, AE_punkt.y, array[i].x, array[i].y);
console.log(array[i].distanz);
if (array[i].distanz != 0) {
if (compare(array[i].distanz, min)) {
min = array[i].distanz;
console.log("Min:" + min);
}
}
}
for (var i = 0; i < array.length; i++) {
if (array[i].distanz = 0) {
array.splice(i, 1); //entfernt den Punkt der dem aktuellen AE_punkt entspricht
}
console.log(array[i]);
}
}
nearestNeighbour();