我怎么能逆时针旋转

时间:2016-04-05 06:05:23

标签: c++ math geometry

这是顺时针旋转的功能。参数是我们想要旋转多少度。 如何将其更改为逆时针旋转?

Sub Capacity2()

With ActiveSheet.Columns("F").SpecialCells(xlCellTypeConstants, xlNumbers) '<= consider only numbers in "availibility code" column
    .Offset(, 3).FormulaR1C1 = "=if(isnumber(search(""-"" & RC[-3] & ""-"",""-762-763-764-765-768-"")),72," _
                                 & "if(RC[-3]=MEDIAN(RC[-3],300,499),181," _
                                 & "if(RC[-3]=MEDIAN(RC[-3],500,599),163," _
                                 & "if(RC[-3]=MEDIAN(RC[-3],600,699),124," _
                                 & "if(RC[-3]=MEDIAN(RC[-3],700,799),144,-1" _
                                 & ")))))"
End With

我们每时每刻旋转1度。

3 个答案:

答案 0 :(得分:1)

void rotateCounterClockwise( int degree ) {
   return rotateClockwise(360 - (360 + degree) % 360);
}

答案 1 :(得分:0)

int rotateClockwise(int degree) {
    return (getDegree() + degree) % 360;
}

int rotateCounterClockwise(int degree) {
    int desiredDegree = (getDegree() - degree%360);
    return desiredDegree >= 0 ? desiredDegree : 360+desiredDegree;
}

答案 2 :(得分:0)

简化它。

你已经有一个旋转方向 - 它是你旋转的角度的标志。

#include <iostream>

struct thing
{
    int rotate(int alpha)
    {
        angle = (angle + alpha) % 360;
        if (angle < 0)
            angle += 360;

        // by all means pre-calculate sin and cos here if you wish.

        return angle;
    }

    int angle;
};

int main(int argc, char * argv[])
{

    auto t = thing { 10 };

    std::cout << t.rotate( 5 ) << std::endl;
    std::cout << t.rotate( -30 ) << std::endl;
    std::cout << t.rotate( 360 + 30 ) << std::endl;
    std::cout << t.rotate( -360 - 40 ) << std::endl;

    return 0;
}

预期结果:

15
345
15
335