@Override // from IRay2 public boolean intersects (IVector pt) { if (Math.abs(direction.x) > Math.abs(direction.y)) { float t = (pt.x() - origin.x) / direction.x; return t >= 0f && origin.y + t*direction.y == pt.y(); } else { float t = (pt.y() - origin.y) / direction.y; return t >= 0f && origin.x + t*direction.x == pt.x(); } }
/** * Sets this to a translation matrix. * * @return a reference to this matrix, for chaining. */ public Matrix3 setToTranslation (IVector translation) { return setToTranslation(translation.x(), translation.y()); }
/** * Sets this to a matrix that first scales, then rotates, then translates. * * @return a reference to this matrix, for chaining. */ public Matrix3 setToTransform (IVector translation, float rotation, IVector scale) { float sx = scale.x(), sy = scale.y(); return setToRotation(rotation).set(m00 * sx, m10 * sy, translation.x(), m01 * sx, m11 * sy, translation.y(), 0f, 0f, 1f); }
/** * Sets this to a matrix that first scales, then rotates, then translates. * * @return a reference to this matrix, for chaining. */ public Matrix3 setToTransform (IVector translation, float rotation, IVector scale) { float sx = scale.x(), sy = scale.y(); return setToRotation(rotation).set(m00 * sx, m10 * sy, translation.x(), m01 * sx, m11 * sy, translation.y(), 0f, 0f, 1f); }
@Override // from Transform 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); }
@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); }
@Override // from Transform 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); }
@Override // from interface IVector public Vector subtract (IVector other, Vector result) { return add(-other.x(), -other.y(), result); }
@Override // from interface IVector public float distanceSq (IVector other) { float dx = x() - other.x(), dy = y() - other.y(); return dx*dx + dy*dy; }
/** * Sets this to a matrix that first scales, then rotates, then translates. * * @return a reference to this matrix, for chaining. */ public Matrix3 setToTransform (IVector translation, float rotation, float scale) { return setToRotation(rotation).set(m00 * scale, m10 * scale, translation.x(), m01 * scale, m11 * scale, translation.y(), 0f, 0f, 1f); }
@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 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 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 // 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 rotateAndAdd (float angle, 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 + add.x(), x*sina + y*cosa + add.y()); }
@Override // from interface IVector public Vector rotateAndAdd (float angle, 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 + add.x(), x*sina + y*cosa + add.y()); }
@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 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()); }