判断交点是否在圆弧上
作者:互联网
通过判断与圆的交点找到交点后,可通过这一步来判断交点是否在圆弧上面
//这个是判断顺时针还是逆时针旋转
if (templine.EndAngle - templine.StartAngle >= 0) direction = true;
else direction = false;
public bool JudgeDotQualified(double[] vector, double[] ptInter1, double startAngle, double endAngle, bool _direction = false)
{
bool retu = false;
if (!_direction)
{
//画弧为逆时针
//得到一个交点对应的弧度
double radian = Tangent(vector[0],vector[1], ptInter1[0],ptInter1[1]);
if (startAngle > endAngle)
{ //起始角度大于终止角度时,交点角度小于终止角度或者交点角度大于起始角度就会与圆弧相交
if (radian <= endAngle || radian >= startAngle)
{
retu = true;
}
}
else
{ //起始角度小于终止角度时,交点角度在起始角度和终止角度之间就会与圆弧相交
if (startAngle < radian && radian < endAngle)
{
retu = true;
}
else if (startAngle == radian || endAngle == radian)
{
retu = true;
}
}
}
else
{
//画弧为顺时针
//得到一个交点对应的弧度
double radian = Tangent(vector[0], vector[1], ptInter1[0],ptInter1[1]);
if (startAngle < endAngle)
{ //起始角度小于终止角度时,交点角度大于终止角度或者交点角度小于起始角度就会与圆弧相交
if (radian <= startAngle || radian >= endAngle)
{
retu = true;
}
}
else
{ //起始角度大于终止角度时,交点角度在终止角度和起始角度之间就会与圆弧相交
if (endAngle < radian && radian < startAngle)
{
retu = true;
}
else if (startAngle == radian || endAngle == radian)
{
retu = true;
}
}
}
return retu;
}
/// 利用正切值
/// 计算交点对应的弧度
public double Tangent(double X1,double Y1,double X2,double Y2)
{
double DegreeToRadian1 = System.Math.Atan2((Y2 - Y1), (X2 - X1)) * 180 / System.Math.PI;
if (DegreeToRadian1 < 0)
{
DegreeToRadian1 = 360 + DegreeToRadian1;
}
return DegreeToRadian(DegreeToRadian1);
}
标签:判断,double,圆弧,角度,radian,retu,交点,startAngle 来源: https://www.cnblogs.com/tangpyODA/p/14435759.html