方法一:
`
///
/// 获取逆时针圆心坐标
///
///
///
///
///
///
///
///
private void CalcCenter(double x1, double y1, double x2, double y2, double theta, out double cx, out double cy)
{
cx = 0;
cy = 0;
if (theta == 0)
{
throw new ArgumentException("thera must not be 0");
}
double t = Math.PI * theta / 180.0;
double sinT = Math.Sin(t);
double cosT = Math.Cos(t);
double temp = 0.5 / (1.0 - cosT);
cx = (x1 + x2) * 0.5 + sinT * (y1 - y2) * temp;
cy = (y1 + y2) * 0.5 + sinT * (x2 - x1) * temp;
}`
方法二:
`
private bool Circle_Center(double x1, double y1, double x2, double y2, double theta, bool isNeg, out double cx, out double cy)
{
cx = 0;
cy = 0;
double dDistance = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
double dRadius = dDistance * 0.5 / Math.Sin(Math.PI / 180 * theta * 0.5);
if (dDistance == 0.0)
{
// cout << "\n输入了相同的点!\n";
return false;
}
if ((2 * dRadius) < dDistance)
{
// cout << "\n两点间距离大于直径!\n";
return false;
}
double k = 0.0, k_verticle = 0.0;
double mid_x = 0.0, mid_y = 0.0;
double a = 1.0;
double b = 1.0;
double c = 1.0;
k = (y2 - y1) / (x2 - x1);
double cx1, cy1, cx2, cy2;
if (k == 0)
{
cx1 = (x1 + x2) / 2.0;
cx2 = (x1 + x2) / 2.0;
cy1 = y1 + Math.Sqrt(dRadius * dRadius - (x1 - x2) * (x1 - x2) / 4.0);
cy2 = y2 - Math.Sqrt(dRadius * dRadius - (x1 - x2) * (x1 - x2) / 4.0);
}
else
{
k_verticle = -1.0 / k;
mid_x = (x1 + x2) / 2.0;
mid_y = (y1 + y2) / 2.0;
a = 1.0 + k_verticle * k_verticle;
b = -2 * mid_x - k_verticle * k_verticle * (x1 + x2);
c = mid_x * mid_x + k_verticle * k_verticle * (x1 + x2) * (x1 + x2) / 4.0 -
(dRadius * dRadius - ((mid_x - x1) * (mid_x - x1) + (mid_y - y1) * (mid_y - y1)));
cx1 = (-1.0 * b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
cx2 = (-1.0 * b - Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
cy1 = Y_Coordinates(mid_x, mid_y, k_verticle, cx1);
cy2 = Y_Coordinates(mid_x, mid_y, k_verticle, cx2);
}
//cx2,cy2为顺时针圆心坐标,cx1,cy1为逆时针圆心坐标
if (isNeg)
{
cx = cx1;
cy = cy1;
}
else
{
cx = cx2;
cy = cy2;
}
return true;
}
private double Y_Coordinates(double x, double y, double k, double x0)
{
return k * x0 - k * x + y;
}
`
标签:double,mid,y1,圆心,坐标,两点,x2,x1,verticle From: https://www.cnblogs.com/diena/p/17549788.html