C#求结直线ax+by+c=0与圆的交点程序
public static void InterC2L ( double centerR, double centerC, double R, double a, double b, double c, out List< double > Rows, out List< double > Columns)
{
Rows = new List< double > ( ) ;
Columns = new List< double > ( ) ;
double dis = DistanceP2L ( centerR, centerC, a, b, c) ;
if ( dis <= R)
{
if ( a == 0 )
{
Columns. Add ( - c / b) ;
Columns. Add ( - c / b) ;
double sub = R * R - ( Columns[ 0 ] - centerC) * ( Columns[ 0 ] - centerC) ;
double kf = Math. Sqrt ( sub) ;
Rows. Add ( - kf + centerR) ;
Rows. Add ( kf + centerR) ;
}
else if ( b == 0 )
{
Rows. Add ( - c / a) ;
Rows. Add ( - c / a) ;
double sub = R * R - ( Rows[ 0 ] - centerR) * ( Rows[ 0 ] - centerR) ;
double kf = Math. Sqrt ( sub) ;
Columns. Add ( centerC - kf) ;
Columns. Add ( kf + centerC) ;
}
else
{
double k = - a / b;
double _b = - c / b;
double equ_a, equ_b, equ_c;
equ_a = 1 + k * k;
equ_b = - 2 * centerR + 2 * k * ( _b - centerC) ;
equ_c = centerR * centerR + ( _b - centerC) * ( _b - centerC) - R * R;
GenEqu2 ( equ_a, equ_b, equ_c, out double res1, out double res2) ;
Rows. Add ( res1) ;
Rows. Add ( res2) ;
double sub = R * R - ( Rows[ 0 ] - centerR) * ( Rows[ 0 ] - centerR) ;
double kf = Math. Sqrt ( sub) ;
double col1 = - kf + centerC;
double col2 = kf + centerC;
if ( Math. Abs ( col1 - ( k * Rows[ 0 ] + _b) ) <= 0.001 )
Columns. Add ( col1) ;
else
Columns. Add ( col2) ;
sub = R * R - ( Rows[ 1 ] - centerR) * ( Rows[ 1 ] - centerR) ;
kf = Math. Sqrt ( sub) ;
col1 = - kf + centerC;
col2 = kf + centerC;
if ( Math. Abs ( col1 - ( k * Rows[ 1 ] + _b) ) <= 0.001 )
Columns. Add ( col1) ;
else
Columns. Add ( col2) ;
}
}
}