2D Object makes my object smaller, Why?

Title should read: 2D Object Rotation makes my object smaller, why?

The problem is that the triangle become smaller and smaller after each rotation for some reason and i dont understand why, im using a formula ive found for the rotation, and its the same on many sites, so i dont know why this is happening. Heres the function that does the rotation.

Code :

public void rotate(double x)
{
double tempX[]=new double[OBJECT_COMPLEXITY]; //points for drawing objects
double tempY[]=new double[OBJECT_COMPLEXITY];
double cosF=Math.cos(x); //x is Math.toRadians(10), negated when going right
double sinF=Math.sin(x);
for(int j=0; j<obj[0].GetPts(); j++) //loop that goes through all the points
{
tempX[j]=obj[0].GetXArray()[j]; //grab the points by value from the array
tempY[j]=obj[0].GetYArray()[j];
System.out.println("#" + j + " Old X: " + tempX[j] + " Old Y: " + tempY[j]);
tempX[j]=tempX[j]*cosF-tempY[j]*sinF; //using online formula
tempY[j]=tempY[j]*cosF+tempX[j]*sinF;
System.out.println("#" + j + " New X: " + tempX[j] + " New Y: " + tempY[j]);
}
System.out.println();
obj[0].SetArrays(tempX, tempY); //send the arrays back to the object
}

Now what i did is turn the triangle 10 degrees to the left, then 10 degrees to the right (yes i converted to radians)

The original array of points::

xObjArr[0]=0;

xObjArr[1]=20;

xObjArr[2]=-20;

yObjArr[0]=-20;

yObjArr[1]=0;

yObjArr[2]=0;

(This is just a triangle)

And now here is the report generated by the rotations, here is the report after rotating to the left:

#0 Old X: 0.0 Old Y: -20.0

#0 New X: -3.4729635533386065 New Y: -19.093081268103244

#1 Old X: 20.0 Old Y: 0.0

#1 New X: 19.69615506024416 New Y: -3.4202014332566866

#2 Old X: -20.0 Old Y: 0.0

#2 New X: -19.69615506024416 New Y: 3.4202014332566866

Here it is when rotating back to the right (it should be noted the size still decreases when turning constantly only in one direction)

#0 Old X: -3.4729635533386065 Old Y: -19.093081268103244

#0 New X: -0.10472266500395477 New Y: -18.821199361658596

#1 Old X: 19.69615506024416 Old Y: -3.4202014332566866

#1 New X: 19.99083795399793 New Y: 0.1031316924119956

#2 Old X: -19.69615506024416 Old Y: 3.4202014332566866

#2 New X: -19.99083795399793 New Y: -0.1031316924119956

Obviously something is wrong, i would be okay with minor imprecisions but this is not even close to the original points.

Can anyone see anything wrong with this, is perhaps the formula wrong???

Re: 2D Object makes my object smaller, Why?

Closely inspect your formula:

Code :

tempX[j]=tempX[j]*cosF-tempY[j]*sinF; //using online formula
tempY[j]=tempY[j]*cosF+tempX[j]*sinF;

The formula is technically correct but should be implemented differently. The formulas are

Code :

x'=x*cos(f) - y*sin(f)
y'= y*cos(f)+x*sin(f)

However, your code does the following when calculating the new Y value.

Code :

y'=y*cos(f) * x' * sin(f)

Re: 2D Object makes my object smaller, Why?

Ahhh, thanks, that did the trick. Ive never incorrectly implemented a formula before, ill be more careful next time.