public double DirectionTo(Coordinate coordTo) { double dir; //Checking for vertical dirction if (coordTo.X == this.X) { if (coordTo.Y == this.Y) { //_start == _end dir = 0; return dir; } //not allowed to divide by zero... if (coordTo.Y > this.Y) //tEnd is north of tStart... dir = 90; //degrees else //tEnd is south of tStart... dir = 270; //degrees return dir; } //Checking for horisontal direction else if (coordTo.Y == this.Y) { //not allowed to divide by zero... if (coordTo.X < this.X) //tEnd is west of tStart... dir = 180; //degrees else //tEnd is east of tStart... dir = 0; //degrees return dir; } dir = Math.Atan((coordTo.Y - this.Y) / (coordTo.X - this.X)); //radians dir = dir * (180.0 / Math.PI); //Converting radians to 360 degress if (coordTo.X < this.X) { if (coordTo.Y > this.Y) //tEnd is northwest of tStart dir = dir + 180; //degrees else if (coordTo.Y < this.Y) //tEnd is southwest of tStart dir = dir + 180; //degrees } //Making sure dir is between 0 and 360 while (dir > 360) { dir = dir - 360; } while (dir < 0) { dir = dir + 360; } return dir; }
public double DirectionFrom(Coordinate coordTo) { return coordTo.DirectionTo(this); }
public double DistanceTo(Coordinate coordTo) { Double dist; dist = Math.Sqrt((Math.Pow((this.X - coordTo.X), 2.0) + Math.Pow((this.Y - coordTo.Y), 2.0))); return dist; }