   Center of Pixels
  I have a bunch of pixels and I want to figure out a good position for the center of rotation of a 2d object based on their positions. How could I do this?I use c++ and direct3d in case it's relevant.Thanks.   
  Compute the center of mass.  Example:cm = (0,0);n = 0;For each position (x,y) in image   If image(x,y) == solid  cm += (x,y);  n++;   endendcm /= n;;  Weird cause that's what I am doing right now and it doesn't seem to work. No matter how many or where the pixels are located it always takes the center of the images/texture as the center of rotation(Unless I change the equation which has some bizarre consequences).float pixelsTotal = 0;currentPixel = 0;while(currentPixel <= size){if(canvasBits[currentPixel] != D3DCOLOR_ARGB(0,0,0,0)){pixelsTotal++;b2Vec2 p = GetPixel(currentPixel, width); //Width is the texture's widthp.x = (p.x/32) * scaling.x;//32 is world coordinates per pixel, scaling is the sprite's current scaling.p.y = (-p.y/32) * scaling.y;localCoords = p + offset;totalCenterOfMass += localCoords;}currentPixel++;}totalCenterOfMass.x /= pixelsTotal;totalCenterOfMass.y /= pixelsTotal;b2Vec2 PlayState::GetPixel(int pixel, int width){int y = (pixel/width),x = (pixel - (y*width));return b2Vec2(x,y);};Quote:Original post by Antonymit always takes the center of the images/texture as the center of rotationCould you re-explain what you're trying to do then because the center of an image is, by definition, the center of the pixels...-me   ;  I want the center of 'solid' pixels(Which I select) instead of all pixels which would be the image as a whole.   ;Quote:Original post by AntonymI want the center of 'solid' pixels(Which I select) instead of all pixels which would be the image as a whole.Define "solid"The only thing I can think is that you have an image with a bunch of transparent pixels and you're trying to find the center of the non-transparent pixels.  In that case modify your code to only average in the non-transparent pixels by running an if check on the alpha channel for each pixel[EDITOh, it looks like you're already trying to do that:if(canvasBits[currentPixel] != D3DCOLOR_ARGB(0,0,0,0)){Step through with a debugger and verify that the pixels you want to skip are actually 0,0,0,0 in value.]-me   ;  It seems to work I added a line of code to change the color of any pixel added to red, only non-alpha pixels changed.   