void Vector2::RotateAround(Vector2 origin, double rotation) { Vector2 fromMid = *this - origin; Vector2 unitVec(1, 0); double angleFrom0 = fromMid.AngleBetween(unitVec); if (fromMid.y < 0) { angleFrom0 *= -1; } angleFrom0 += rotation; Vector2 endMove(cos(angleFrom0), sin(angleFrom0)); endMove *= fromMid.Magnitude(); endMove = origin + endMove; *this = endMove; }
Vector2 Vector2::RotateAround(Vector2 origin, float rotation) const { if (rotation == 0) { return *this; } Vector2 fromMid = *this - origin; Vector2 unitVec(1, 0); float angleFrom0 = fromMid.AngleBetween(unitVec); angleFrom0 -= rotation; Vector2 endMove(cos(angleFrom0), sin(angleFrom0)); endMove *= fromMid.Magnitude(); endMove = origin + endMove; return endMove; }