I’ve dealt with this issue in a 2d environment. You want to do a “affine transformation” (Affine transformation - Wikipedia).
Basically, the solution is to skip all the hard math. Do what UnrealEverything said - move to the origin, rotate, move back. Saves you a lot of headaches, even if doesn’t sound like a “proper” way