/// <summary> /// 用给定点(必须在圆弧上,否则返回圆弧自身)截取圆弧 /// </summary> /// <param name="point"></param> /// <param name="bCuteEnd">返回截取后得第一段还是第二段圆弧(true:第一段)</param> /// <returns></returns> public ArcSegment CutebyPoint(Point3D point, bool bCuteEnd) { PointArcRelationShipType ship = this.GetRelationShipWithPoint(point); if (ship == PointArcRelationShipType.On_ArcSegment) { if (bCuteEnd == true) { return(new ArcSegment(this.Center, this.BeginPoint, point, this.ArcDirection)); } else { return(new ArcSegment(this.Center, point, this.EndPoint, this.ArcDirection)); } } else { return(this); } #region Old Method //if (ship != PointArcRelationShipType.In_ArcSegment_Center //点在圆弧与圆心之间 // && ship != PointArcRelationShipType.To_ArcSegment_Center //点在圆弧所在方位 // && ship != PointArcRelationShipType.On_ArcSegment) //点在圆弧上 //{ // return this; //} //return new ArcSegment(Center, Radius, ArcDirection, bCuteEnd ? BeginRadian : Center.DirTo(point), // bCuteEnd ? Center.DirTo(point) : EndRadian); #endregion }
/// <summary> /// 判断点是否在圆弧线段上 /// </summary> /// <param name="point"></param> /// <returns></returns> public override bool PointIsOnCurveSegment(Point3D point) { PointArcRelationShipType type = GetRelationShipWithPoint(point); if (type == PointArcRelationShipType.On_ArcSegment) { return(true); } return(false); }
/// <summary> /// 根据圆弧上的一点把圆弧截为两个子圆弧 /// </summary> /// <param name="point"></param> /// <returns></returns> public override List <CurveSegment> CuteOutbyPoint(Point3D point) { PointArcRelationShipType ship = this.GetRelationShipWithPoint(point); if (ship == PointArcRelationShipType.On_ArcSegment) { List <CurveSegment> list = new List <CurveSegment>(); list.Add(new ArcSegment(this.Center, this.BeginPoint, point, this.ArcDirection)); list.Add(new ArcSegment(this.Center, point, this.EndPoint, this.ArcDirection)); return(list); } else { return(new List <CurveSegment>() { this }); } }
/// <summary> /// 给定直线段,计算圆弧和直线段所在直线间的公切圆,并返回满足指定半径的圆弧 /// </summary> /// <param name="line"></param> /// <param name="radius"></param> /// <returns></returns> public List <ArcSegment> GetCommonTangentArcsbyArcandLine(LineSegment line, double radius) { List <ArcSegment> list = new List <ArcSegment>(); List <Point3D> cacheList = new List <Point3D>(); double dir = line.GetDirection(); LineSegment line1 = line.CopyMove(dir - Math.PI / 2, radius) as LineSegment; //公切圆圆心所在的直线1 LineSegment line2 = line.CopyMove(dir + Math.PI / 2, radius) as LineSegment; //公切圆圆心所在的直线2 var r = this.Radius + radius; var r2 = Math.Abs(this.Radius - radius); //构造假想圆弧 ArcSegment arc = new ArcSegment(this.Center, r); ArcSegment arc2 = new ArcSegment(this.Center, r2); //1.如果圆弧与直线相切,最多存在四个所求圆 //2.如果圆弧与直线相交,最多存在八个所求圆 //3.如果圆弧与直线相离,可能存在两个所求圆 LineArcRelationShipType lineArcRelationShipType = GetRelationShipwithLine(line); if (lineArcRelationShipType == LineArcRelationShipType.Tangent || lineArcRelationShipType == LineArcRelationShipType.TangentWithArc) { var list1 = arc.GetIntersectPointsWithLine(line1); if (list1 != null && list1.Count > 0) { cacheList.AddRange(list1); } var list2 = arc2.GetIntersectPointsWithLine(line1); if (list2 != null && list2.Count > 0) { cacheList.AddRange(list2); } var list3 = arc.GetIntersectPointsWithLine(line2); if (list3 != null && list3.Count > 0) { cacheList.AddRange(list3); } var list4 = arc2.GetIntersectPointsWithLine(line2); if (list4 != null && list4.Count > 0) { cacheList.AddRange(list4); } } else if (lineArcRelationShipType == LineArcRelationShipType.Insert || lineArcRelationShipType == LineArcRelationShipType.InsertWithArc || lineArcRelationShipType == LineArcRelationShipType.InsertWithArcSegmentAndArc) { var list1 = arc.GetIntersectPointsWithLine(line1); if (list1 != null && list1.Count > 0) { cacheList.AddRange(list1); } var list2 = arc2.GetIntersectPointsWithLine(line1); if (list2 != null && list2.Count > 0) { cacheList.AddRange(list2); } var list3 = arc.GetIntersectPointsWithLine(line2); if (list3 != null && list3.Count > 0) { cacheList.AddRange(list3); } var list4 = arc2.GetIntersectPointsWithLine(line2); if (list4 != null && list4.Count > 0) { cacheList.AddRange(list4); } } else if (lineArcRelationShipType == LineArcRelationShipType.Apart) { var list1 = arc.GetIntersectPointsWithLine(line1); if (list1 != null && list1.Count > 0) { cacheList.AddRange(list1); } var list2 = arc.GetIntersectPointsWithLine(line2); if (list2 != null && list2.Count > 0) { cacheList.AddRange(list2); } } else if (lineArcRelationShipType == LineArcRelationShipType.Others) { return(null); } foreach (Point3D p in cacheList) { PointArcRelationShipType t = GetRelationShipWithPoint(p); if (t == PointArcRelationShipType.On_ArcSegment || t == PointArcRelationShipType.In_ArcSegment_Center || t == PointArcRelationShipType.To_ArcSegment_Center) { list.Add(new ArcSegment(p, radius)); } } return(list); }
/// <summary> /// 点和圆弧位置关系具体测试方法 /// </summary> /// <param name="Full"></param> /// <param name="Part"></param> private void GetRelationShipWithPoint_SubTest(ArcSegment Full, ArcSegment Part) { //Case 1: 点在圆弧上(整圆) Point3D point = new Point3D() { X = 1, Y = 0, Z = 0 }; PointArcRelationShipType type = Full.GetRelationShipWithPoint(point); Assert.AreEqual(type, PointArcRelationShipType.On_ArcSegment); //Case 2: 点在圆弧上(1/4圆) Point3D point2 = new Point3D() { X = 1, Y = 0, Z = 0 }; PointArcRelationShipType type2 = Part.GetRelationShipWithPoint(point2); Assert.AreEqual(type2, PointArcRelationShipType.On_ArcSegment); //Case 3: 点在圆弧外(整圆)点在圆弧所在方位 Point3D point3 = new Point3D() { X = 2, Y = 0, Z = 0 }; PointArcRelationShipType type3 = Full.GetRelationShipWithPoint(point3); Assert.AreEqual(type3, PointArcRelationShipType.To_ArcSegment_Center); //Case 4: 点在圆弧外(1/4圆)点在圆弧所在方位 Point3D point4 = new Point3D() { X = 2, Y = 0, Z = 0 }; PointArcRelationShipType type4 = Part.GetRelationShipWithPoint(point4); Assert.AreEqual(type4, PointArcRelationShipType.To_ArcSegment_Center); //Case 5: 点在圆弧所在的圆上,但不在圆弧上(1/4圆适用) Point3D point5 = new Point3D() { X = -1, Y = 0, Z = 0 }; PointArcRelationShipType type5 = Part.GetRelationShipWithPoint(point5); Assert.AreEqual(type5, PointArcRelationShipType.On_Arc); //Case 6: 点在圆弧所在的圆内,但不在圆弧和圆心之间(1/4圆适用) Point3D point6 = new Point3D() { X = -0.1, Y = 0.1, Z = 0 }; PointArcRelationShipType type6 = Part.GetRelationShipWithPoint(point6); Assert.AreEqual(type6, PointArcRelationShipType.In_Arc); //Case 7: 点在圆弧与圆心之间(1/4圆) Point3D point7 = new Point3D() { X = 0.1, Y = 0.1, Z = 0 }; PointArcRelationShipType type7 = Part.GetRelationShipWithPoint(point7); Assert.AreEqual(type7, PointArcRelationShipType.In_ArcSegment_Center); //Case 8: 点在圆弧与圆心之间(整圆) Point3D point8 = new Point3D() { X = 0.1, Y = 0.1, Z = 0 }; PointArcRelationShipType type8 = Full.GetRelationShipWithPoint(point8); Assert.AreEqual(type8, PointArcRelationShipType.In_ArcSegment_Center); //Case 9: 点在圆弧外,点在圆弧背离的方位(1/4圆) Point3D point9 = new Point3D() { X = -2, Y = -2, Z = 0 }; PointArcRelationShipType type9 = Part.GetRelationShipWithPoint(point9); Assert.AreEqual(type9, PointArcRelationShipType.Back_ArcSegment_Center); }