本文介绍了修改了C#中旋转矩形的右端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人

我在图片框中绘制一个旋转的矩形(45度角).我知道原点(左上角)是矩形的(x = 5,y = 15);我想要终点(右角).任何人都可以帮助我.

Dear All

I draw a rotated rectangle (angle 45) in a picture box. i know the origin point (Left Top Corner) is (x=5,y=15) of the rectangle; i want the the end point (Right Corner). any one help me.

推荐答案


//Some declarations, sort of 'default settings', these should only be calculated when the rectangle is initialised or resized.
float defaultAngle = 45; //The default Angle so calculations still point to the lower right corner when it hasn't been rotated yet.
PointF center = new PointF(width/2,height/2);
float Radius = Math.Sqrt(Math.Pow(width - Center.X,2) + Math.Pow(height - Center.Y)); // Distance between the center and the lower right corner.

//The point calculations, to be done whenever the rectangle is being rotated.
fullAngle = defaultAngle + yourAngle; //yourAngle is the rotation of the rectangle.
PointF BottomRightCorner = new PointF(0,0); //Point in which we will store the 
BottomRightCorner.X = center.X + Math.Cos(Radians(fullAngle)) * Radius; // The parameter for Math.Cos requires the angle in radians.
BottomRightCorner.Y = center.Y + Math.Sin(Radians(fullAngle)) * Radius; //Same goes for Math.Sin .
//BottomRightCorner should now contain the position of the bottom right corner.


-


--

float Radians(float Degrees)
{
 return Degrees * (Math.PI /180); //Simple conversion form degrees to radians.
}


这篇关于修改了C#中旋转矩形的右端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:11