public void GetRelationShipWithArcTest() { //Case1:相离 ArcSegment other1 = new ArcSegment(new Point3D() { X = 4, Y = 0, Z = 0 }, 2); ArcSegmentArcRelationShipType result11 = this.ArcSegment_Full.GetRelationShipWithArc(other1); Assert.AreEqual(result11, ArcSegmentArcRelationShipType.Apart); ArcSegmentArcRelationShipType result12 = this.ArcSegment_Part.GetRelationShipWithArc(other1); Assert.AreEqual(result12, ArcSegmentArcRelationShipType.Apart); //Case2: 内切 ArcSegment other2 = new ArcSegment(new Point3D() { X = 4, Y = 0, Z = 0 }, 5); ArcSegmentArcRelationShipType result21 = this.ArcSegment_Full.GetRelationShipWithArc(other2); Assert.AreEqual(result21, ArcSegmentArcRelationShipType.InnerTangent); ArcSegmentArcRelationShipType result22 = this.ArcSegment_Part.GetRelationShipWithArc(other2); Assert.AreEqual(result22, ArcSegmentArcRelationShipType.InnerTangent); //Case3: 外切 ArcSegment other3 = new ArcSegment(new Point3D() { X = 4, Y = 0, Z = 0 }, 3); ArcSegmentArcRelationShipType result31 = this.ArcSegment_Full.GetRelationShipWithArc(other3); Assert.AreEqual(result31, ArcSegmentArcRelationShipType.OuterTangent); ArcSegmentArcRelationShipType result32 = this.ArcSegment_Part.GetRelationShipWithArc(other3); Assert.AreEqual(result32, ArcSegmentArcRelationShipType.OuterTangent); //Case4: 相交 ArcSegment other4 = new ArcSegment(new Point3D() { X = 4, Y = 0, Z = 0 }, 4); ArcSegmentArcRelationShipType result41 = this.ArcSegment_Full.GetRelationShipWithArc(other4); Assert.AreEqual(result41, ArcSegmentArcRelationShipType.Insert); ArcSegmentArcRelationShipType result42 = this.ArcSegment_Part.GetRelationShipWithArc(other4); Assert.AreEqual(result42, ArcSegmentArcRelationShipType.Insert); }
/// <summary> /// 给定圆弧,计算圆弧与圆弧之间的公切线段集合 /// </summary> /// <param name="rightArcSegment"></param> /// <returns></returns> public List <LineSegment> GetCommonTangentLinebyArcs(ArcSegment other) { ArcSegment leftArcSegment = null; ArcSegment rightArcSegment = null; if (this.Center.X < other.Center.X) { leftArcSegment = this; rightArcSegment = other; } else { leftArcSegment = other; rightArcSegment = this; } ArcSegmentArcRelationShipType type = leftArcSegment.GetRelationShipWithArc(rightArcSegment); //相交,外切,相离会用到两条 if (type == ArcSegmentArcRelationShipType.Insert || type == ArcSegmentArcRelationShipType.Apart || type == ArcSegmentArcRelationShipType.OuterTangent) { double r1 = leftArcSegment.Radius; double r2 = rightArcSegment.Radius; double dis = leftArcSegment.Center.DisTo(rightArcSegment.Center); double x = Math.Abs(dis * r1 / (r2 - r1)); double angle = Math.Asin(r1 / x); double dir0 = new LineSegment(leftArcSegment.Center, rightArcSegment.Center).GetDirection() - Math.PI / 2; LineSegment lineRadius = null; LineSegment lineRadius2 = null; if (r1 > r2) { lineRadius = new LineSegment(leftArcSegment.Center, rightArcSegment.Center); lineRadius.Rotate(leftArcSegment.Center, angle, ArcDirctionType.CLOCK_WISE); lineRadius.Move(dir0 + angle, r1); lineRadius2 = new LineSegment(leftArcSegment.Center, rightArcSegment.Center); lineRadius2.Rotate(leftArcSegment.Center, angle, ArcDirctionType.UNCLOCK_WISE); lineRadius2.Move(dir0 + Math.PI - angle, r1); } else { lineRadius = new LineSegment(leftArcSegment.Center, rightArcSegment.Center); lineRadius.Rotate(leftArcSegment.Center, angle, ArcDirctionType.UNCLOCK_WISE); lineRadius.Move(dir0 - angle, r1); lineRadius2 = new LineSegment(leftArcSegment.Center, rightArcSegment.Center); lineRadius2.Rotate(leftArcSegment.Center, angle, ArcDirctionType.CLOCK_WISE); lineRadius2.Move(dir0 - Math.PI + angle, r1); } List <LineSegment> list = new List <LineSegment>(); if (leftArcSegment.GetRelationShipwithLine(lineRadius) == LineArcRelationShipType.Tangent && rightArcSegment.GetRelationShipwithLine(lineRadius) == LineArcRelationShipType.Tangent) { list.Add(lineRadius); } if (leftArcSegment.GetRelationShipwithLine(lineRadius2) == LineArcRelationShipType.Tangent && rightArcSegment.GetRelationShipwithLine(lineRadius2) == LineArcRelationShipType.Tangent) { list.Add(lineRadius2); } return(list); } return(null); }