Пример #1
0
        /** Creates an affine transform from the supplied scale, rotation and translation. */
        public AffineTransform(float scaleX, float scaleY, float angle, float tx, float ty)
        {
            float sina = FloatMath.Sin(angle), cosa = FloatMath.Cos(angle);

            this.m00 = cosa * scaleX; this.m01 = sina * scaleY;
            this.m10 = -sina * scaleX; this.m11 = cosa * scaleY;
            this.Tx  = tx;            this.Ty = ty;
        }
Пример #2
0
        /** Inverse transforms a point as specified, storing the result in the point provided.
         * @return a reference to the result point, for chaining. */
        public static Point InverseTransform(float x, float y, float sx, float sy, float rotation,
                                             float tx, float ty)
        {
            x -= tx; y -= ty;                       // untranslate
            float sinnega = FloatMath.Sin(-rotation), cosnega = FloatMath.Cos(-rotation);
            float nx = (x * cosnega - y * sinnega); // unrotate
            float ny = (x * sinnega + y * cosnega);

            return(new Point(nx / sx, ny / sy)); // unscale
        }
Пример #3
0
 /**
  * Rounds a value to the nearest multiple of a target.
  */
 public static float RoundNearest(float v, float target)
 {
     target = Math.Abs(target);
     if (v >= 0)
     {
         return(target * FloatMath.Floor((v + 0.5f * target) / target));
     }
     else
     {
         return(target * FloatMath.Ceiling((v - 0.5f * target) / target));
     }
 }
Пример #4
0
        public Transform Rotate(float angle)
        {
            float otx = this.Tx, oty = this.Ty;

            if (otx != 0 || oty != 0)
            {
                float sina = FloatMath.Sin(angle);
                float cosa = FloatMath.Cos(angle);
                this.Tx = otx * cosa - oty * sina;
                this.Ty = otx * sina + oty * cosa;
            }
            this.Rotation += angle;
            return(this);
        }
Пример #5
0
        public Transform PreConcatenate(Transform other)
        {
            if (this.Generality < other.Generality)
            {
                return(other.Concatenate(this));
            }

            float sina = FloatMath.Sin(other.Rotation), cosa = FloatMath.Cos(other.Rotation);
            float ntx       = (Tx * cosa - Ty * sina) * other.ScaleX + other.Tx;
            float nty       = (Tx * sina + Ty * cosa) * other.ScaleY + other.Ty;
            float nrotation = MathUtil.NormalizeAngle(other.Rotation + this.Rotation);
            float nscaleX   = other.ScaleX * this.ScaleX;
            float nscaleY   = other.ScaleY * this.ScaleY;

            return(new NonUniformTransform(nscaleX, nscaleY, nrotation, ntx, nty));
        }
Пример #6
0
 /**
  * Returns a random value according to the exponential distribution with the provided mean.
  *
  * @param random a uniformly distributed random value.
  * @param mean the desired mean.
  */
 public static float Exponential(float random, float mean)
 {
     return(-FloatMath.Log(1f - random) * mean);
 }
Пример #7
0
        public Transform Rotate(float angle)
        {
            float sina = FloatMath.Sin(angle), cosa = FloatMath.Cos(angle);

            return(Transforms.Multiply(cosa, sina, -sina, cosa, 0, 0, this, this));
        }
Пример #8
0
 /** Transforms a point as specified, storing the result in the point provided.
  * @return a reference to the result point, for chaining. */
 public static Point Transform(float x, float y, float sx, float sy, float rotation,
                               float tx, float ty)
 {
     return(Transform(x, y, sx, sy, FloatMath.Sin(rotation), FloatMath.Cos(rotation), tx, ty));
 }
Пример #9
0
        public Point Rotate(float angle)
        {
            float sina = FloatMath.Sin(angle), cosa = FloatMath.Cos(angle);

            return(new Point(x * cosa - y * sina, x * sina + y * cosa));
        }
Пример #10
0
        public float AngleBetween(Vector other)
        {
            float cos = Dot(other) / (this.Length * other.Length);

            return(cos >= 1f ? 0f : FloatMath.Acos(cos));
        }
Пример #11
0
 public float Distance(Vector other)
 {
     return(FloatMath.Sqrt(DistanceSq(other)));
 }
Пример #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));
        }
Пример #13
0
        public Vector Rotate(float angle)
        {
            float sina = FloatMath.Sin(angle), cosa = FloatMath.Cos(angle);

            return(new Vector(x * cosa - y * sina, x * sina + y * cosa));
        }
Пример #14
0
 /**
  * Returns the magnitude of the specified vector.
  */
 public static float Length(float x, float y)
 {
     return(FloatMath.Sqrt(LengthSq(x, y)));
 }
Пример #15
0
 /**
  * Returns the Euclidean distance between the specified two points.
  */
 public static float Distance(float x1, float y1, float x2, float y2)
 {
     return(FloatMath.Sqrt(DistanceSq(x1, y1, x2, y2)));
 }
Пример #16
0
 /**
  * Transforms a vector as specified.
  */
 public static Vector Transform(float x, float y, float sx, float sy, float rotation)
 {
     return(Transform(x, y, sx, sy, FloatMath.Sin(rotation), FloatMath.Cos(rotation)));
 }
Пример #17
0
 public float Direction(Point other)
 {
     return(FloatMath.Atan2(other.y - y, other.x - x));
 }