【发布时间】:2021-08-25 20:39:36
【问题描述】:
我正在尝试以编程方式找到通过围绕其原点旋转矢量创建的点(可能在 2D 空间中的任何位置)。
我们看到我们在 (x, y) 的某个点上有我们的线(或数学向量)A,它可能位于 2D 空间中的任何位置。它在某个 (x, y) 处运行到点 B。我们将它旋转 Theta,然后移动到 (x, y) 处的某个点 C。对我来说,问题在于尝试以编程方式使用数学来解决这些问题。
最初的想法是形成一个三角形并使用 trig,但这个角度可能正好是 180(不太可能但可能),显然没有三角形可以工作。有人有想法吗?
我正在使用 C# 和我自己的矢量对象(如下)来测试线条的创建。任何帮助表示赞赏!
struct Vector2D {
double x, y, theta;
Vector2D(double x, double y) {
(this.x, this.y) = (x, y);
theta = x != 0 ? Math.Atan(y / x) : 0;
}
double Magnitude() {
return Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
}
(double,double) PointFromRotation(double angle) {
// This is where I need some help...
return (0,0); // hopefully a point of x and y from the angle argument
}
}
【问题讨论】:
-
听起来像线性变换是你的朋友吗?您可以将向量平移到原点
(0,0),然后使用旋转矩阵对其进行旋转,然后将其平移回原始位置。