coddding - 1 year ago 65

C++ Question

Ok, so I'm making this fun little game in c++, unfortunately I'm stuck on making a "radar", I'm stuck on this part

(EDIT, i already have

`A`

`B`

`C`

`D`

So what i need to do is calculate the two points (

`2d vector`

`C`

`D`

`B`

`A`

`C`

`D`

`B`

`C`

`D`

`D`

`B`

`B`

`A`

`A`

`A`

`C`

`D`

`B`

`A`

What would be like the best way to make a lil function for this calculation?

e.g.

`inline float returnDPoint(float A, float B)`

{

float dPoint;

//calculate point of D based off A & B

return dPoint;

}

inline float returnCPoint(float A, float B)

{

float cPoint;

//calculate point of C based off A & B

return cPoint;

}

Hopefully i have worded my question well enough, thanks for the read!

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Since you are looking for rotations by 90°, you don't need to use expensive functions such as `atan2`

, `sqrt`

, etc. A simple alternative would be:

```
diffx = bx - ax;
diffy = by - ay;
cx = ax - diffy = ax - by + ay;
cy = ay + diffx = ay + bx - ax;
dx = ax + diffy = ax + by - ay;
dy = ay - diffx = ay - bx + ax;
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**