how do I rotate a filled rectangle

Hi,

I am using MIDP1. I have a filled rectangle and I need to rotate it. How can I do that since the Graphics object does not have a rotate method?

I have tried to rotate it manually using sin and cos, but then the rectangle moved in a circle path. >:( and is not what I wanna. I wanna move the filled rectangle around its axis.

I am working on 2D.

You can find many sites out there that are devoted to this type of subject. Here is a link that might be helpful: http://www.cs.brown.edu/people/scd/facts.html

Also, your not going to be able to use sin and cos as there is no built in functions for that in midp. What you can do is write a simple program in C or some other language to print out a list of sin and cos computations for each degree of rotation and then put those into your midp program and use it in a lookup table.

Sounds like luisoft’s problem is not the maths but the fact that MIDP’s fillRectangle doesn’t handle rotation.

You’ll probably achieve what you want by splitting the rectangle into two triangles and using fillTriangle for each. The edge where the two triangles meet will be drawn twice, but this shouldn’t be a problem since MIDP 2.0 doesn’t support XOR mode or semi-transparent colours.

yeah my problem is exactly that. Why they have put a fillTriangle and not a fillPolygon? >:( I will try your solution davidaprince. I’ve also heard about a implementation of a fillPolygon for J2ME that is opensource, but I really don’t know how fast it is.

Maybe because fillTriangle is much easier to implement than fillPolygon ;). And if you have fillTriangle, you can implement fillPolygon trivially, at least for convex polygons (actually, rectangle is just a special case of this).

But I agree, they ought to include fillPolygon in MIDP 3.0. If you’re using a Nokia device, this feature is already available in the Nokia UI API.