2017-01-11 34 views
1

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

image

A是要绕C

由于ACB & D将随A移动,并停留在基于断的地方A是相同的“位置”。

因此,举例来说,如果A各地C旋转90度B & D会再移动,并在这个位置

image

但我不是在TRIG非常好,所以我真的不知道我需要的数学才能找到B & D根据多少A已经旋转了大约C

如何找到B & D基于关闭的多少A各地C已经转动?

我会像最终的数学看起来有点类似于此:

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]; 
+0

http://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d – SingerOfTheFall

+0

你知道A围绕C旋转的角度吗? – acraig5075

回答

1

所以,你知道A的相对位置的2D对于C.可以说,这是(AX,AY)。

如果叉积(0,0,1)与(AX,AY,0)你会发现d的相对位置,这将是类似的信息(DX,DY,0)

d =(DX ,DY)是D. b的相对位置也通过执行简单的矩阵乘法,这给出了变换点(x0, y0)以下等式-d

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

4

可以旋转的一个点(x, y)围绕原点:

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