2D vectors and rotation.

I’m building a simple little vector game in 2D. I have a vector class which simply holds X and Y co-ordinates and have used three of these to create a little triangle spaceship. The co-ordinates are based about the arbitary origin posX and posY - which just happens to be the centre of the screen.

How do I go about rotating the points around this arbitary origin? Should I temporarily reset the posX and posY to (0,0) rotate and then move back to the arbitary origin or can I rotate the points where they are?

How I see it :

  1. for the shape, store the coordinates around the (0,0) position
  2. when rendering, rotate the shape first then translate it to the ship position.

By the way, java 2D allready have everything to deal with this. You can use for example GeneralPath to store shapes. Use AffinTransform to rotate/translate it. And then use a Graphics2D.draw().

and if you want to rotate them by hand around an arbitrary axis :

angle : rotation angle in Radians
axisX : x pos for rotation center
axisY : y pos for rotation center

class VectorXXX
{
	double x;
	double y;
	public void rotate(double angle,double axisX,double axisY)
	{
		double tY=y-axisX,tX=x-axisY;
		double cosa=Math.cos(angle);
		double sina=Math.sin(angle);
		x=tX*cosa + tY*sina + axisX;
		y=-tX*sina + tY*cosa + axisY;
	}
}

NB: adapted from 3DzzD not tested but should work