Rotate a point around another point

#include<bits/stdc++.h>
#define ll long long

// Rotate point around another point. COUNTER-clockwise
pair<double, double> rotate_point_around_point(
    pair<double, double> point, pair<double, double> center, double ndegrees) {
    
    double angle = ndegrees * PI / 180.;
    
    pair<double, double> new_point;
    new_point.first  = cos(angle) * (point.first - center.first) - sin(angle) * (point.second - center.second) + center.first;
    new_point.second = sin(angle) * (point.first - center.first) + cos(angle) * (point.second - center.second) + center.second;
    
    return new_point;
}

Leave a Reply