public static double AngleBetween(Vector v1, Vector v2) { double val = Dot (v1, v2) / (v1.Length * v2.Length); val = Math.Acos (val); if (!Right (v1, v2)) return -val; return val; }
bool DragUpdate() { if (!dragging) return false; if (!rotate) { return MoveWindow (); } else { Gdk.Point initial = start_root; Gdk.Point hot = start_hot; Gdk.Point win = Gdk.Point.Zero; hot.X += win.X; hot.Y += win.Y; initial.X -= hot.X; initial.Y -= hot.Y; Gdk.Point now = root_pos; now.X -= hot.X; now.Y -= hot.Y; var v1 = new Vector (initial); var v2 = new Vector (now); double angleBetween = Vector.AngleBetween (v1, v2); Angle = start_angle + angleBetween; return false; } }
public double AngleBetween(Vector v) { return AngleBetween (this, v); }
public static double Dot(Vector v1, Vector v2) { return v1.X * v2.X + v1.Y * v2.Y; }
static bool Right(Vector v1, Vector v2) { return (v1.X * v2.Y - v1.Y * v2.X) > 0; }