1

我在 2 点 A(100, 100) 和 B(100, 200) 之间画了一条线,我想围绕 A 点旋转 x 度。显然,该代码仅适用于 45 度。我试过90度,它看起来很不对劲。我希望有人能够指出什么是错的。

float newX = 100.0f;
float newY = 100.0f;
float newX1 = 100.0f;
float newY1 = 200.0f;
float degree = 90.0;
float x, y;
x = newX1;
y = newY1;
x -= newX;
y -= newY;
newX1 = (x * cos(degree)) - (y * sin(degree));
newY1 = (x * sin(degree)) + (y * cos(degree));
newX1 += newX;
newY1 += newY;
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, newX, newY);
CGContextAddLineToPoint(ctx, newX1, newY1);
CGContextStrokePath(ctx);
4

0 回答 0