/** * Transforms a vector as specified, storing the result in the vector provided. * @return a reference to the result vector, for chaining. */ public static Vector transform (float x, float y, float sx, float sy, float sina, float cosa, Vector result) { return result.set((x*cosa - y*sina) * sx, (x*sina + y*cosa) * sy); }
/** Transforms a vector as specified (as a point, accounting for translation), storing the * result in the vector provided. * @return a reference to the result vector, for chaining. */ public static Vector transform (float x, float y, float sx, float sy, float sina, float cosa, float tx, float ty, Vector result) { return result.set((x*cosa - y*sina) * sx + tx, (x*sina + y*cosa) * sy + ty); }
@Override // from IMatrix3 public Vector transformVector (IVector vector, Vector result) { float vx = vector.x(), vy = vector.y(); return result.set(m00*vx + m10*vy, m01*vx + m11*vy); }
@Override // from Transform public Vector transform (IVector v, Vector into) { float x = v.x(), y = v.y(); return into.set(m00*x + m10*y, m01*x + m11*y); }
/** Copies the elements of another vector. * @return a reference to this vector, for chaining. */ public Vector set (XY other) { return set(other.x(), other.y()); }
/** * Inverse transforms a vector as specified, storing the result in the vector provided. * @return a reference to the result vector, for chaining. */ public static Vector inverseTransform (float x, float y, float sx, float sy, float rotation, Vector result) { float sinnega = FloatMath.sin(-rotation), cosnega = FloatMath.cos(-rotation); float nx = (x * cosnega - y * sinnega); // unrotate float ny = (x * sinnega + y * cosnega); return result.set(nx / sx, ny / sy); // unscale }
@Override // from IMatrix3 public Vector transformPoint (IVector point, Vector result) { float px = point.x(), py = point.y(); return result.set(m00*px + m10*py + m20, m01*px + m11*py + m21); }
@Override // from Transform public Vector inverseTransform (IVector v, Vector into) { 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 into.set((x * m11 - y * m10) * rdet, (y * m00 - x * m01) * rdet); }
/** * Sets this vector's angle, preserving its magnitude. * @return a reference to this vector, for chaining. */ public Vector setAngle (float angle) { float l = length(); return set(l * FloatMath.cos(angle), l * FloatMath.sin(angle)); }
@Override // from interface IVector public Vector rotate (float angle, Vector result) { float x = x(), y = y(); float sina = FloatMath.sin(angle), cosa = FloatMath.cos(angle); return result.set(x*cosa - y*sina, x*sina + y*cosa); }
@Override // from interface IVector public Vector lerp (IVector other, float t, Vector result) { float x = x(), y = y(); float dx = other.x() - x, dy = other.y() - y; return result.set(x + t*dx, y + t*dy); }
@Override // from interface IVector public Vector cross (IVector other, Vector result) { float x = x(), y = y(), ox = other.x(), oy = other.y(); return result.set(y*ox - x*oy, x*oy - y*ox); }
@Override // from interface IVector public Vector rotate (float angle, Vector result) { float x = x(), y = y(); float sina = FloatMath.sin(angle), cosa = FloatMath.cos(angle); return result.set(x*cosa - y*sina, x*sina + y*cosa); }
@Override public Vector inverseTransform(IVector v, Vector into) { float m00 = m00(), m01 = m01(), m10 = m10(), m11 = m11(); 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 into.set((x * m11 - y * m10) * rdet, (y * m00 - x * m01) * rdet); }
@Override public Vector transform(IVector v, Vector into) { float x = v.x(), y = v.y(); return into.set(m00() * x + m10() * y, m01() * x + m11() * y); }
@Override // from interface IVector public Vector rotateScaleAndAdd (float angle, float scale, IVector add, Vector result) { float x = x(), y = y(); float sina = FloatMath.sin(angle), cosa = FloatMath.cos(angle); return result.set((x*cosa - y*sina)*scale + add.x(), (x*sina + y*cosa)*scale + add.y()); }
@Override // from interface IVector public Vector rotateScaleAndAdd (float angle, float scale, IVector add, Vector result) { float x = x(), y = y(); float sina = FloatMath.sin(angle), cosa = FloatMath.cos(angle); return result.set((x*cosa - y*sina)*scale + add.x(), (x*sina + y*cosa)*scale + add.y()); }
@Override public Vector transformPoint (IVector v, Vector into) { float x = v.x(), y = v.y(); return into.set(m00()*x + m10()*y + tx(), m01()*x + m11()*y + ty()); }