iwidth, iheight为自定义画布的长宽。(x1,y1),(x2,y3),(x3,y3),(x4,y4)为4四个不在一条线上的随机点。
Bitmap image = new Bitmap(iwidth, iheight);
Graphics Image3 = Graphics.FromImage(image);
Image3.Clear(Color.White);//背景
Pen pen = new Pen(Color.Red, 1);//画笔
double xLeft = x1; double yTop = y1; double xRight = x2; double yBottom = y2;
double xStart = x3; double yStart = y3; double xEnd = x4; double yEnd = y4;
//C#方法DrawArc的关键点参数
double x, y, width, height, startAngle, sweepAngle;
//startAngle椭圆中心点从x正轴顺时针起始角度,sweepAngle扫过的角度
//1.
x = xLeft; //左起始点x坐标
y = yTop; //左起始点y坐标
width = xRight - xLeft; //椭圆矩形宽度
height = yBottom - yTop; //椭圆矩形高度
//2.求圓心
double xc = x + width / 2;
double yc = y + width / 2;
//3.计算半径
double R = width / 2;
//4.计算起始点方向角
double cos_cita = (xStart - xc) / R;
const double PI = 3.14;
startAngle = Math.Acos(cos_cita) / PI * 180;
startAngle += 90; //acos计算出来是逆时针方向,需要转换成C#是顺时针方向,
//说明:根据现有数据得出的圆心是在梁图的下缘,与实际不符。且这个计算的起始角是X正轴逆时针所得,下方终止角也是
//所以下方画图方法将此角度转换成x正轴顺时针,并且将中心点放到梁图上缘查看,画的图才是所要的,所以需要从终止角开始画弧
//5.计算终止点方向角
cos_cita = (xEnd - xc) / R;
double endAngle = Math.Acos(cos_cita) / PI * 180;
endAngle += 90;
//6.计算旋转角
sweepAngle = startAngle - endAngle;
//绘制曲线
Image3.DrawArc(pen, (float)(x), (float)(y), (float)(width), (float)(height), (float)(endAngle - 90), (float)(sweepAngle));