public double AngleTo(Vector other) { var dotProduct = DotProduct(other); var crossProduct = CrossProduct(other); var angle = Math.Acos( dotProduct / (Length * other.Length) ).ToDegrees(); var otherWay = crossProduct < 0; return otherWay ? (360 - angle) : angle; }
private double SliderAngle(PointerRoutedEventArgs e) { var centre = new Point( ActualWidth / 2, ActualHeight / 2 ); var thumb = e.GetCurrentPoint(this) .Position.RelativeTo(centre); var vertical = new Vector(0, -1); return thumb.AngleTo(vertical); }
private double HalfAngle(Size size, double radius) { var thickness = (double)GetValue(Halo.ThicknessProperty); var width = new Vector( Math.Cos(Offset.ToRadians()) * size.Width, Math.Sin(Offset.ToRadians()) * size.Height ).Length; var height = new Vector( Math.Sin(Offset.ToRadians()) * size.Width, Math.Cos(Offset.ToRadians()) * size.Height ).Length; return Math.Atan2( width/2, radius - thickness/2 - height/2 ).ToDegrees(); }
public double DotProduct(Vector other) { return (X * other.X) + (Y * other.Y); }
public double CrossProduct(Vector other) { return (Y * other.X) - (X * other.Y); }