image processing - Calculating the center of rotation after translation -
i need able rotate image around given point ever part of image appears in center of container center of rotation.
to calculate center points, taking inverse of translation applied image:
rotate.centerx = translate.x * -1; rotate.centery = translate.y * -1;
however, current calculation i'm using not sufficient not work if image has been translated after being rotated.
i'm sure it's reasonably straight forward trig function, can't think is!
cheers
if working gdi+ use following:
double imwidth = (double)im.width; double imheight = (double)im.height; double xtrans = -(imwidth * x); double ytrans = -(imheight * y); g.translatetransform((float)xtrans, (float)ytrans); g.translatetransform((float)(imwidth / 2.0 - xtrans), (float)(imheight / 2.0 - ytrans)); g.rotatetransform((float)angle); g.translatetransform(-((float)(imwidth / 2.0 - xtrans)), -((float)(imheight / 2.0 - ytrans)));
if working wpf graphic objects, use following transform group:
transformgroup tc = new transformgroup(); rotatetransform rt = new rotatetransform(angle); rt.centerx = im.width / 2.0; rt.centery = im.height / 2.0; translatetransform tt = new translatetransform(-x * im.pixelwidth, -y * im.pixelheight); tc.children.add(tt); tc.children.add(rt);
x & y percent values want translate image in (if image 1000 pixels , x 0.1 image translated 100 pixels). how needed function work can change otherwise.
Comments
Post a Comment