public void rotate(double theta)
    {

        // this is the matrix to multiply by..
        //x*cos(theta) , y* sin(theta) 
        //  x* -sin(theta)
        //y * cos(theta)

        vertices[0][0]=  vertices[0][0]* Math.cos(theta)+  Math.sin(theta)*vertices[0][1];
        vertices[0][1]=  vertices[0][0] * (-Math.sin(theta)) +  Math.cos(theta)*vertices[0][1];

        vertices[1][0]=  vertices[1][0]* Math.cos(theta)+ Math.sin(theta)*vertices[1][1];
        vertices[1][1]=  vertices[1][0] * (-Math.sin(theta)) + Math.cos(theta)*vertices[1][1];

        vertices[2][0]=  vertices[2][0]* Math.cos(theta)+ Math.sin(theta)*vertices[2][1];
        vertices[2][1]=  vertices[2][0] * (-Math.sin(theta)) +   Math.cos(theta)*vertices[2][1];

        vertices[3][0]=  vertices[3][0]* Math.cos(theta)+ Math.sin(theta)*vertices[3][1];
        vertices[3][1]=  vertices[3][0] * (-Math.sin(theta)) +  Math.cos(theta)*vertices[3][1] ;
    }

I want to rotate a simple square object by a passed number of degrees by using a rotation matrix. I have gotten to a point where although it rotates, it has a very wide rotation field, it's more of an orbit than a rotation it's not quite working! I wonder does anyone have any ideas what's wrong?

Where is the centre of rotation (is it the top left corner?)

I guess that rotates about the 0,0 origin of your coordinate system.

If you want to rotate about (say) the center of the object you can:
translate the object so the centre of the object is at the origin
rotate the object
translate it back to the original position
(translation is a trival add/subtract to every vertex)

there may be a smarter way, but I'm no expert.

My panel is 500 x 500, and my object starts bang in the middle before rotation, so I presume this is 250,250 on the axis.
I have a transform method, so what you're saying is I need to transform by 250,250 to move the object to where I actually have it in the window, and then after rotation, transform -250,-250 to go back to my object origon?

Center of rotation seems to be let's say -100,-100 from the middle of the panel.

I had this problem a while back using AffineTransforms, and solved it like that. Eg if you want to rotate about the center of the object, move it so its center is at the center of rotation (normlly 0,0 of your coordinate system), rotarte it, then reverse the original translation to put the object back where it belongs.
With your figures that would be
translate -100, -100
rotate
translate 100, 100

But I'm no expert, and there's probably a better way that I don't know about.

Well I'll give that a try, it sounds about right as I've researched the rotations quite a lot, and it talks of the order of transformations, I never knew what they meant but I guess if you have 2 transforms and a rotation, then order would come into it.

Aside from your snide remarks on other threads, thank you, that worked.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.