/// <summary> /// Gets the angle this vector is at in relationship to another Vector. /// Take note that 0 degrees increases clockwise. /// </summary> /// <param name="src"></param> /// <returns></returns> public double GetAngleFromClockwise(Vector2D src) { double angle = 0.0d; // We are within 0° - 180°. if (this.Y > src.Y) { // We are in Quadrant I (0° - 90°). if (this.X > src.X) { angle = (double)(this.X - src.X) / (double)(this.Y - src.Y); angle = Math.Atan(angle); angle = 90 - Mathlib.ToDegrees(angle); } else if (this.X < src.X) { // We are in Quadrant II (91° - 180°). angle = (double)(src.X - this.X) / (double)(this.Y - src.Y); angle = Math.Atan(-angle); angle = 90 - Mathlib.ToDegrees(angle); } else if (this.X == src.X) { // We are between Quadrant I and II (90°). angle = 90; } } else if (this.Y < src.Y) { // We are in Quadrant III (180° - 270°). if (this.X < src.X) { angle = (double)(src.X - this.X) / (double)(src.Y - this.Y); angle = Math.Atan(angle); angle = 270 - Mathlib.ToDegrees(angle); } // We are in Quadrant IV (271° - 360°). else if (this.X > src.X) { angle = (double)(this.X - src.X) / (double)(src.Y - this.Y); angle = Math.Atan(-angle); angle = 270 - Mathlib.ToDegrees(angle); } // We are between Quadrant III and IV (270°). else if (this.X == src.X) { angle = 270; } } else if (this.Y == src.Y) { // We are at 180°. if (this.X < src.X) { angle = 180; } // We are at 0° or 360°. else if (this.X > src.X) { angle = 0; } } return(angle); }
/// <summary> /// Returns the current theta (facing) of this vector in Degrees. /// </summary> /// <returns></returns> public double GetThetaAsDegree() { double angle = GetThetaAsRadian(); return(Mathlib.ToDegrees(angle)); }