【问题标题】:Find 2 points based off how much a point has rotated around a center point根据一个点围绕中心点旋转了多少找到 2 个点
【发布时间】:2017-05-25 19:32:53
【问题描述】:

我正在制作一个小游戏,现在我正在研究“雷达”。现在要做到这一点,我需要根据一个点围绕中心点旋转了多少来找到两个点。

A 将围绕C 旋转。

A 围绕C 旋转时,BD 将与A 一起移动,并根据A 的位置保持相同的“位置”。

例如,如果A 围绕C 旋转90 度BD 将移动并处于此位置

但我不太擅长三角,所以我真的不知道根据A 围绕C 旋转了多少来找到BD 所需的数学。

我如何根据A 围绕C 旋转了多少找到BD

我会想象最终的数学看起来和这个有点相似:

float * returnB(float * APoint, float * CPoint)
{
    float B_Out[2];
    //calculate where B is based off A & C
    B_Out[0] = B_X;
    B_Out[1] = B_Y;
    return B_Out;
}

float B[2];
B[0] = returnB(A,C)[0];
B[1] = returnB(A,C)[1];

float * returnD(float * APoint, float * CPoint)
{
    float D_Out[2];
    //calculate where D is based off A & C
    D_Out[0] = D_X;
    D_Out[1] = D_Y;
    return D_Out;
}

float D[2];
D[0] = returnD(A,C)[0];
D[1] = returnD(A,C)[1];

【问题讨论】:

标签: c++ math rotation trigonometry 2d-vector


【解决方案1】:

您可以通过执行简单的矩阵乘法来围绕原点旋转一个点(x, y),它为转换后的点(x0, y0) 提供以下等式:

x0 = x * cos(theta) - y * sin(theta);
y0 = x * sin(theta) + y * cos(theta);

【讨论】:

    【解决方案2】:

    所以你知道 A 相对于 C 的相对 2d 位置。假设它是 (ax, ay)。

    如果你将 product(0,0,1) 与 (ax, ay, 0) 相乘,你会发现 D 的相对位置类似于 (dx, dy, 0)

    d = (dx, dy) 是 D 的相对位置。 b 也是 -d

    https://en.wikipedia.org/wiki/Cross_product

    【讨论】:

      猜你喜欢
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      • 2014-12-26
      • 2022-01-05
      • 2023-04-03
      • 2017-03-25
      相关资源
      最近更新 更多