Proper Trigonometry For Rotating A Point Around The Origin

后端 未结 3 421
悲哀的现实
悲哀的现实 2020-12-10 12:05

Do either of the below approaches use the correct mathematics for rotating a point? If so, which one is correct?

POINT rotate_point(float cx,float cy,float          


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 12:44

    This is extracted from my own vector library..

    //----------------------------------------------------------------------------------
    // Returns clockwise-rotated vector, using given angle and centered at vector
    //----------------------------------------------------------------------------------
    CVector2D   CVector2D::RotateVector(float fThetaRadian, const CVector2D& vector) const
    {
        // Basically still similar operation with rotation on origin
        // except we treat given rotation center (vector) as our origin now
        float fNewX = this->X - vector.X;
        float fNewY = this->Y - vector.Y;
    
        CVector2D vectorRes(    cosf(fThetaRadian)* fNewX - sinf(fThetaRadian)* fNewY,
                                sinf(fThetaRadian)* fNewX + cosf(fThetaRadian)* fNewY);
        vectorRes += vector;
        return vectorRes;
    }
    

提交回复
热议问题