public clsPoint Intersect(clsArc c1) { double a = 0; double b = 0; double c = 0; double xc = 0; double yc = 0; double lambda1 = 0; double lambda2 = 0; if (c1.Centre.Dist(this) > c1.Radius) { return(null); } xc = c1.Centre.X; yc = c1.Centre.Y; a = Pow((X2 - X1), 2) + Pow((Y2 - Y1), 2); b = 2 * ((X2 - X1) * (X1 - xc) + (Y2 - Y1) * (Y1 - yc)); c = Pow((X1 - xc), 2) + Pow((Y1 - yc), 2) - Pow((c1.Radius), 2); lambda1 = (-b + Sqrt(Abs(Pow(b, 2) - 4 * a * c))) / (2 * a); lambda2 = (-b - Sqrt(Abs(Pow(b, 2) - 4 * a * c))) / (2 * a); if (lambda2 < lambda1 & lambda2 > 0) { lambda1 = lambda2; } return(new clsPoint(X1 + lambda1 * (X2 - X1), Y1 + lambda1 * (Y2 - Y1))); }
public clsArc ArcTanPlus(bool atStart, bool downSide, bool avoidLeadInOut = false) { clsPoint pt1; double a1; double a2; clsArc c1; if (atStart == true) { pt1 = P1; } else { pt1 = P2; } if (downSide) { a1 = 3 * PI / 2; a2 = 3 * PI / 2 + Angle; } else { a1 = 3 * PI / 2 + Angle; a2 = 3 * PI / 2 + PI / 4; } c1 = new clsArc(new clsPoint(pt1.x - 250 * Sin(Angle), pt1.y + 250 * Cos(Angle)), 250, a1, a2, 1); if (avoidLeadInOut == false) { if (downSide) { c1.Move(-c1.EndStraight()); } else { c1.Move(c1.StartStraight()); } } return(c1); }
public static clsLine LineTangentToArcs(clsCircle c1, clsCircle c2, int n = -1) { clsArc myArc1 = new clsArc(); clsArc myArc2 = new clsArc(); //n is the solution number, from 1 to 4 (see document SolutionsToTangencies.doc) //1 = Plus - Minus //2 = Plus - Plus //3 = Minus - Minus //4 = Minus - Plus //In this case, you must pass in an arc if (n == -1) { myArc1 = (clsArc)c1; myArc2 = (clsArc)c2; if (myArc1.Direction == 1 & myArc2.Direction == -1) { n = 1; } if (myArc1.Direction == 1 & myArc2.Direction == 1) { n = 2; } if (myArc1.Direction == -1 & myArc2.Direction == -1) { n = 3; } if (myArc1.Direction == -1 & myArc2.Direction == 1) { n = 4; } } double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 0; double r1 = 0; double r2 = 0; double d = 0; double theta = 0; double alpha = 0; double a = 0; clsPoint p1 = new clsPoint(); clsPoint p2 = new clsPoint(); x1 = c1.Centre.X; y1 = c1.Centre.Y; x2 = c2.Centre.X; y2 = c2.Centre.Y; r1 = c1.Radius; r2 = c2.Radius; d = Sqrt(Pow((x2 - x1), 2) + Pow((y2 - y1), 2)); theta = Angle(x1, y1, x2, y2); if (n == 1) { if (d < r1 + r2) { return(null); } alpha = Acos((r1 + r2) / d); a = theta - alpha; p1 = new clsPoint(x1 + r1 * Cos(a), y1 + r1 * Sin(a)); p2 = new clsPoint(x2 - r2 * Cos(a), y2 - r2 * Sin(a)); } else if (n == 2) { if (d < Abs(r2 - r1)) { return(null); } alpha = Acos((r2 - r1) / d); a = alpha - theta; p1 = new clsPoint(x1 + r1 * Cos(a), y1 - r1 * Sin(a)); p2 = new clsPoint(x2 + r2 * Cos(a), y2 - r2 * Sin(a)); } else if (n == 3) { if (d < Abs(r2 - r1)) { return(null); } alpha = PI / 2 + Asin((r2 - r1) / d); a = alpha + theta; p1 = new clsPoint(x1 + r1 * Cos(a), y1 + r1 * Sin(a)); p2 = new clsPoint(x2 + r2 * Cos(a), y2 + r2 * Sin(a)); } else if (n == 4) { if (d < r1 + r2) { return(null); } alpha = Acos((r1 + r2) / d); a = theta + alpha; p1 = new clsPoint(x1 + r1 * Cos(a), y1 + r1 * Sin(a)); p2 = new clsPoint(x2 - r2 * Cos(a), y2 - r2 * Sin(a)); } else { return(null); } return(new clsLine(p1, p2)); }