我有一个关于按给定中心旋转椭圆的问题,假设我有一个椭圆,应该是按用户给定的点旋转该椭圆,并且椭圆应该围绕该给定点旋转。我试过了
g.RotateTransform(…)
g.TranslateTransform(…)代码:
Graphics g = this.GetGraphics();
g.RotateTransform((float)degreeArg); //degree to rotate object
g.DrawEllipse(Pens.Red, 300, 300, 100, 200);这工作得很好,但是我们如何给出我们的外中心来旋转椭圆……
怎么可能请任何朋友都可以推荐……谢谢……。
发布于 2011-03-14 20:41:43
RotateTransform始终绕原点旋转。因此,您需要首先将旋转中心平移到原点,然后旋转,然后再将其平移回来。
如下所示:
Graphics g = this.GetGraphics();
g.TranslateTransform(300,300);
g.RotateTransform((float)degreeArg); //degree to rotate object
g.TranslateTransform(-300,-300);
g.DrawEllipse(Pens.Red, 300, 300, 100, 200);发布于 2011-03-14 21:03:53
//center of the rotation
PointF center = new PointF(...);
//angle in degrees
float angle = 45.0f;
//use a rotation matrix
using (Matrix rotate = new Matrix())
{
//used to restore g.Transform previous state
GraphicsContainer container = g.BeginContainer();
//create the rotation matrix
rotate.RotateAt(angle, center);
//add it to g.Transform
g.Transform = rotate;
//draw what you want
...
//restore g.Transform state
g.EndContainer(container);
}https://stackoverflow.com/questions/5298226
复制相似问题