/** 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; }
/** 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 }
/** * 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)); } }
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); }
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)); }
/** * 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); }
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)); }
/** 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)); }
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)); }
public float AngleBetween(Vector other) { float cos = Dot(other) / (this.Length * other.Length); return(cos >= 1f ? 0f : FloatMath.Acos(cos)); }
public float Distance(Vector other) { return(FloatMath.Sqrt(DistanceSq(other))); }
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)); }
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)); }
/** * Returns the magnitude of the specified vector. */ public static float Length(float x, float y) { return(FloatMath.Sqrt(LengthSq(x, y))); }
/** * 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))); }
/** * 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))); }
public float Direction(Point other) { return(FloatMath.Atan2(other.y - y, other.x - x)); }