/// <summary> /// Gets the angle in degrees between this vector and another. /// </summary> /// <param name="other">The other vector to get the angle to.</param> /// <remarks>See http://en.wikipedia.org/wiki/Dot_product</remarks> public decimal AngleTo(Vector2D other) { if (this.IsNull || other.IsNull) { throw new Exception("Can't find angle when one or both vectors are null vectors!"); } // Cos(theta) = DotProduct(v1,v2) / (length(v1) * length(v2)) // aka theta = acos(v.normalize.dot(other.normalize)), however, the equation // used gives us better precision return(DecimalEx.ToDeg(DecimalEx.ACos(this.Dot(other) / (this.Magnitude * other.Magnitude)))); }
/// <summary> /// Gets angle in degrees from the adjacent side and the hypotenuse. /// </summary> /// <param name="adjacentSide">Length of the known side adjacent to the angle.</param> /// <param name="hypotenuse">Length of the hypotenuse.</param> public static decimal GetAngleFromAdjSideHyp(decimal adjacentSide, decimal hypotenuse) { // cos(a) = adjacentSide / hypotenuse // a = acos(adjacentSide / hypotenuse) return(DecimalEx.ToDeg(DecimalEx.ACos(adjacentSide / hypotenuse))); }