# pixel rectangle precise rotating [closed]

Take a look at this my question at stackoverflow.com, please. My goal is to avoid of purple borders around red rectangle. I get this vertical rectangles by rotating same-sized strongly red horizontal rectangles through its geometrical center. Best explanation of appearing of purple pixels is: this is a transform artifact. It happens if you rotate around a point that is not exactly on a full pixel (not so precise definition), so your transformed element ends up occupying half pixels on screen which the transform tries to mitigate with subpixel blending. So, my question is - which ratio should satisfy the width/height parameters of rectangle for better avoiding of this?

-

## closed as off topic by Steven Stadnicki, LVK, Michael Greinecker♦, William, J. M.Aug 31 '12 at 10:01

Questions on Mathematics Stack Exchange are expected to relate to math within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

while I expect this question to be closed as being unsuited for math.SE (it's wholly about implementation details of the transformation), I'll note that as you posed the question it's not clear that the dimensions of the rectangle have anything at all to do with it. – Steven Stadnicki Aug 15 '12 at 23:25
I have no idea what program you're using, but can't you just turn interpolation off? – Robert Mastragostino Aug 16 '12 at 0:00
@StevenStadnicki it is not about implementation. I could not change rotating-algorithm, only width and height of rectangle. – scythargon Aug 16 '12 at 0:12
@RobertMastragostino no:( I could not change rotating-algorithm, only width and height of rectangle. – scythargon Aug 16 '12 at 0:13
But it's entirely about implementation. Where are pixel-centers at, are they on whole numbers or on half-numbers? What parameters does the rotation function take? – Steven Stadnicki Aug 16 '12 at 1:18

To expand my comment into a proper answer, based on my impression of what's going on: I'm going to presume that you're rotating by $90^\circ$ and want the edges of your rectangle to remain on pixel boundaries as opposed to half-pixel boundaries. In that case, as I said in the comment, the key is that your rectangle's width and height should both be of the same parity (i.e. either both odd or both even).
Here's the rough explanation: suppose that your rectangle covers the area from $(0,0)$ to $(w,h)$. Then its center will be at $(w/2, h/2)$ with the horizontal edges at $w/2\pm w/2$ (i.e., $0$ and $w$) and the vertical edges at $h/2\pm h/2$. after rotating by $90^\circ$, the center stays the same but now the width and height are interchanged; the horizontal edges are at $w/2\pm h/2$ and the vertical edges at $h/2\pm w/2$. Note that if any of these is a whole number, then all of them are; and since for instance $w/2+h/2 = (w+h)/2$ the condition that any are whole numbers is precisely the condition that $w+h$ is divisible by two, or that $w$ and $h$ have the same parity.
I mean if any of the four quantities representing the edges ($a=w/2+h/2$, $b=w/2-h/2$, $c=h/2+w/2$ and $d=h/2-w/2$) is an integer, then all of them are. $a=c$ and $b=-d$ so those are obvious, but if $a$ is an integer then $b$ must be because $b=a-h$, and likewise if $b$ is an integer then $a$ must be because $a=b+h$. – Steven Stadnicki Aug 16 '12 at 18:35
To be honest, I don't feel like I can any better than I have already tried. Instead, why don't you try? First plug in let's say $w=200,h=100$ to see what happens and where your rotated rectangle goes; then plug in $w=150,h=75$ to see what goes wrong; then plug in $w=175,h=75$ to see why the answer is '$w$ and $h$ have to have the same parity' and not just '$w$ and $h$ both have to be even'. – Steven Stadnicki Aug 17 '12 at 0:11