1

I am making a little game and I am now working on a "radar". Now to do this I need to find two points based off how much a point has rotated around a center point.

image

A is going to rotate around C.

As A rotates around C, B & D will move along with A and stay in the same "positions" based off of where A is.

So for example, if A rotates around C 90 degrees B & D would then move and be in this position

image

But I am not very good at trig, so I don't really know the math I would need in order to find B & D based off how much A has rotated around C.

How do i find B & D based off of how much A has rotated around C?

I would image the final math would look somewhat similar to this:

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];
coddding
  • 333
  • 1
  • 6
  • 15

2 Answers2

4

You can rotate a point (x, y) around the origin by performing a simple matrix multiplication, which gives the following equations for the transformed point (x0, y0):

x0 = x * cos(theta) - y * sin(theta);
y0 = x * sin(theta) + y * cos(theta);
Joseph Thomson
  • 9,888
  • 1
  • 34
  • 38
1

So you know A's relative 2d position respect to C. Lets say it is (ax, ay).

If you cross product(0,0,1) with (ax, ay, 0) you will find relative position of D that will be something like (dx, dy, 0)

d = (dx, dy) is relative position of D. b is also -d

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

ataman
  • 341
  • 4
  • 18