改变坐标系

时间:2010-06-30 07:49:30

标签: math geometry c++-cli gdi+ gdi

alt text

我需要使用System :: Drawing :: Drawing2D(即GDI +)从上面显示的XY坐标系统切换到X'Y'坐标系统。这就是我的想法:

float rotation =                    // +90 below is because AB is the new vertical...
    Math::Atan2(pB.Y - pA.Y, pB.X - pA.X) * 180.0 / Math::PI + 90.0f;

Matrix m;
m.Translate(pA.X, pA.Y);
m.Rotate(rotation);
m.Invert();

array<PointF> points = gcnew array<PointF>{ pC };
m.TransformPoints(points);

有没有办法在最小化舍入错误的同时执行此操作?我可以在这里避免Atan2(或其他反三角函数)调用吗?

1 个答案:

答案 0 :(得分:3)

我不熟悉gdi +,但原则上你可以在没有反向触发或运算符反转的情况下做到这一点。 (我说“运算符反转”而不是“矩阵反转”,因为Matrix对我来说看起来不像矩阵。)

首先,您应该能够通过更改定义运算符的方式来避免矩阵求逆。这是一个盲目的刺:

Matrix m;
m.Rotate(-rotation);
m.Translate(-pA.X, -pA.Y);

现在对于旋转本身,通常的方法是使用如下矩阵:

cos(theta)  -sin(theta)
sin(theta)   cos(theta)

你正在使用atan(y / x)计算theta。但是如果你想要的是罪和cos,你可以将x和y标准化并直接使用它们:

x  -y
y   x

不需要atan。 实际上,根本没有触发!

相关问题