Collision detection with rotating crosses (or similar)

let’s say the middle point of your rotating fan/cross is at _origin and the fan’s blades have a length of 10.

Let’s you have 4 blades ( a cross) and right now it is unrotated. One blade is top, one is right bottom left etc.

So the blade to the right should have the position 10, 0 at the start right?

But for rotation we need to calculate the sins and cosines, I tried to make it into a simple function:

_origin = new Vector2(0,0);
_bladeLength = 10;
_cross.angle = 0;

(…)

//rotate!
_cross.angle += 0.1f;

// Calculate the end points of the blades!

//Calculate the position from the angle
float sin0 = (float) Math.sin(_cross.angle);
float cos0 = (float) Math.cos(_cross.angle);

_blade1.position.x = sin0 * bladeLength + _origin.x;
_blade1.position.y = cos0*bladeLength + _origin.y;

//The opposite blade simply has the negative sin/cos values

_blade2.position.x = -sin0 * bladeLength + _origin.x;
_blade2.position.y = -cos0*bladeLength + _origin.y;

//Now for the other 2 blades we need to take the angle and add 90°, aka half pi

sin0 = Math.sin(_cross.angle + Math.PI/2);
cos0 = Math.cos(_cross.angle + Math.PI/2);

_blade3.position.x = sin0 * bladeLength + _origin.x;
_blade3.position.y = cos0bladeLength + _origin.y;
_blade4.position.x = -sin0 * bladeLength + _origin.x;
_blade4.position.y = -cos0
bladeLength + _origin.y;

Hope this helps

1 Like