public static double PointToLine(PCADPoint p,PCADLine line)
{
//PCADVector v1 = p - line.startPoint;
//PCADVector v2 = line.endPoint - line.startPoint;
//double radian = DotProduct(v1, v2);
//double dis = Math.Sin(v1.length);
//return dis;
double x1 = line.startPoint.x;
double y1 = line.startPoint.y;
double x2 = line.endPoint.x;
double y2 = line.endPoint.y;
double A = y2 - y1;
double B = x1 - x2;
double C = x2 * y1 - x1 * y2;//直线方程1
double dis = (A * p.x + B * p.y + C) / Math.Sqrt(A * A + B * B);
return -dis;
}
public static double LineToLine(PCADLine line1, PCADLine line2)
{
double x1 = line1.startPoint.x;
double y1 = line1.startPoint.y;
double x2 = line1.endPoint.x;
double y2 = line1.endPoint.y;
double A = y2 - y1;
double B = x1 - x2;
double C = x2 * y1 - x1 * y2;//直线方程1
double x11 = line2.startPoint.x;
double y11 = line2.startPoint.y;
double x22 = line2.endPoint.x;
double y22 = line2.endPoint.y;
double A2 = y22 - y11;
double B2 = x11 - x22;
double C2= x22 * y11 - x11 * y22;//直线方程2
double dis = Math.Abs((C - C2)) / Math.Sqrt((A * A2) + (B * B2));
return dis;
}