Esempio n. 1
0
 public Vector InverseTransform(Vector v)
 {
     float x = v.x, y = v.y;
     float det = m00 * m11 - m01 * m10;
     if (Math.Abs(det) == 0f) {
     // determinant is zero; matrix is not invertible
     throw new NoninvertibleTransformException(this.ToString());
     }
     float rdet = 1 / det;
     return new Vector((x * m11 - y * m10) * rdet,
                 (y * m00 - x * m01) * rdet);
 }
Esempio n. 2
0
 public Vector Transform(Vector v)
 {
     float x = v.x, y = v.y;
     return new Vector(m00*x + m10*y, m01*x + m11*y);
 }
Esempio n. 3
0
 public float DistanceSq(Vector other)
 {
     float dx = x - other.x, dy = y - other.y;
     return dx*dx + dy*dy;
 }
Esempio n. 4
0
 public float Dot(Vector other)
 {
     return x*other.x + y*other.y;
 }
Esempio n. 5
0
 public float AngleBetween(Vector other)
 {
     float cos = Dot(other) / (this.Length * other.Length);
     return cos >= 1f ? 0f : FloatMath.Acos(cos);
 }
Esempio n. 6
0
 public float Distance(Vector other)
 {
     return FloatMath.Sqrt(DistanceSq(other));
 }
Esempio n. 7
0
 public Vector Add(Vector other)
 {
     return Add(other.x, other.y);
 }
 public Vector Transform(Vector v)
 {
     return Vectors.Transform(v.x, v.y, ScaleX, ScaleY, Rotation);
 }
Esempio n. 9
0
 public Vector Scale(Vector other)
 {
     return new Vector(x*other.x, y*other.y);
 }
Esempio n. 10
0
 public Vector Subtract(Vector other)
 {
     return Add(-other.x, -other.y);
 }
Esempio n. 11
0
 public Vector RotateScaleAndAdd(float angle, float scale, Vector add)
 {
     float sina = FloatMath.Sin(angle), cosa = FloatMath.Cos(angle);
     return new Vector((x*cosa - y*sina)*scale + add.x,
                   (x*sina + y*cosa)*scale + add.y);
 }
Esempio n. 12
0
 public Vector RotateAndAdd(float angle, Vector add)
 {
     float sina = FloatMath.Sin(angle), cosa = FloatMath.Cos(angle);
     return new Vector(x*cosa - y*sina + add.x, x*sina + y*cosa + add.y);
 }
Esempio n. 13
0
 public Vector Lerp(Vector other, float t, Vector result)
 {
     float dx = other.x - x, dy = other.y - y;
     return new Vector(x + t*dx, y + t*dy);
 }
Esempio n. 14
0
 /**
  * Returns true if the supplied vectors' x and y components are equal to one another within
  * {@link MathUtil#EPSILON}.
  */
 public static bool EpsilonEquals(Vector v1, Vector v2)
 {
     return EpsilonEquals(v1, v2, MathUtil.EPSILON);
 }
Esempio n. 15
0
 public Vector AddScaled(Vector other, float v)
 {
     return new Vector(x + other.x*v, y + other.y*v);
 }
Esempio n. 16
0
 /**
  * Returns true if the supplied vectors' x and y components are equal to one another within
  * {@code epsilon}.
  */
 public static bool EpsilonEquals(Vector v1, Vector v2, float epsilon)
 {
     return Math.Abs(v1.x - v2.x) <= epsilon && Math.Abs(v1.y - v2.y) <= epsilon;
 }
Esempio n. 17
0
 public Transform Invert()
 {
     Vector iscale = new Vector(1f / ScaleX, 1f / ScaleY);
     Vector t = new Vector(Tx, Ty).Negate().Rotate(-Rotation).Scale(iscale);
     return new NonUniformTransform(iscale.x, iscale.y, -Rotation, t.x, t.y);
 }