改变坐标系 [英] Changing co-ordinate system
问题描述
我需要从上面显示的XY坐标系统切换到使用System :: Drawing :: Drawing2D(即GDI +)的X'Y'坐标系统。这是我想到的:
I need to switch from the XY co-ordinate system shown above to the X'Y' co-ordinate system using System::Drawing::Drawing2D (i.e. GDI+). This is what I have in mind:
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
(或其他反三角函数)调用吗?
Is there a way to do this while minimizing rounding errors? Can I avoid the Atan2
(or other inverse trigonometric function) call here?
推荐答案
我不熟悉gdi +,但原则上你可以做这个没有反向trig或操作符反转。 (我说操作符反转而不是矩阵反转,因为 Matrix
看起来不像是一个矩阵。)
I'm not familiar with gdi+, but in principle you can do this without inverse trig or operator inversion. (I say "operator inversion" instead of "matrix inversion" because this Matrix
doesn't look like a matrix to me.)
首先,你应该能够通过改变你定义运算符的方式来避免矩阵求逆。这里有一个盲目的刺:
First, you should be able to avoid the matrix inversion by changing the way you define the operator. Here's a blind stab at it:
Matrix m;
m.Rotate(-rotation);
m.Translate(-pA.X, -pA.Y);
现在对于旋转本身,通常的方法是使用一个矩阵,
Now for the rotation itself, the usual way to do it is with a matrix that looks like this:
cos(theta) -sin(theta)
sin(theta) cos(theta)
您正在使用atan(y / x)计算theta。但是如果你想要的是罪和cos,你可以正规化x和y并直接使用它们:
and you're calculating theta using atan(y/x). But if what you want are the sin and cos, you can just normalize x and y and use them directly:
x -y
y x
不需要atan。 其实,根本没有trig!
这篇关于改变坐标系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!