Esempio n. 1
0
 private float Angle(Vector vec1, Vector vec2)
 {
     float angle = (float)Math.Atan2(vec1.X * vec2.Y - vec2.X * vec1.Y, vec1.X * vec2.X + vec1.Y * vec2.Y);
     return angle % (2 * (float)Math.PI);
 }
Esempio n. 2
0
            public override ToolState UpdatePointerSequence(PointerEventInfo info, ILevelGeometry viewport)
            {
                Vector vecCenter = new Vector(InitialPosition.X, InitialPosition.Y);
                Vector vec1 = new Vector(InitialLocation.X, InitialLocation.Y) - vecCenter;
                Vector vec2 = new Vector((float)info.X, (float)info.Y) - vecCenter;

                Vector imgCenter = new Vector(InitialCenter.X, InitialCenter.Y);

                Vector originWorking = new Vector(InitialPosition.X, InitialPosition.Y) - imgCenter;

                float angle = Angle(vec1, vec2);

                float s = (float)Math.Sin(angle);
                float c = (float)Math.Cos(angle);

                Vector originPrime = new Vector(
                    originWorking.X * c - originWorking.Y * s,
                    originWorking.X * s + originWorking.Y * c);

                originPrime += imgCenter;

                HitObject.Position = new Point((int)originPrime.X, (int)originPrime.Y);
                HitObject.Rotation = InitialAngle + angle;

                return this;
            }
Esempio n. 3
0
 public static float DistanceSquared(Vector v1, Vector v2)
 {
     float x = v1.X - v2.X;
     float y = v1.Y - v2.Y;
     return (x * x + y * y);
 }
Esempio n. 4
0
 public static float Angle(Vector vec1, Vector vec2)
 {
     float dot = Vector.Dot(vec1, vec2);
     dot = dot / (vec1.Length * vec2.Length);
     return (float)Math.Acos(dot);
 }
Esempio n. 5
0
 public bool Equals(Vector other)
 {
     return this.X == other.X && this.Y == other.Y;
 }
Esempio n. 6
0
 public static float Dot(Vector v1, Vector v2)
 {
     return (v1.X * v2.X) + (v1.Y * v2.Y);
 }