/// <summary> /// 三点绘制圆弧 /// </summary> /// <param name="db">图形数据库</param> /// <param name="startPoint3d">起点坐标</param> /// <param name="pointOnArc">圆弧上的点</param> /// <param name="endPoint3d">重点坐标</param> /// <returns></returns> public static ObjectId AddArcToModelSpace(this Database db, Point3d startPoint3d, Point3d pointOnArc, Point3d endPoint3d) { //判断三点是否在同一条直线上 if (startPoint3d.IsOnOneLine(pointOnArc, endPoint3d)) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("3个顶点在同一条直线上,无法绘制圆弧"); return(ObjectId.Null); } //创建几何对象 CircularArc3d CArc = new CircularArc3d(startPoint3d, pointOnArc, endPoint3d); //获取几何对象的属性 double radius = CArc.Radius; //半径 Point3d conter = CArc.Center; //圆心 //Vector3d cs = conter.GetVectorTo(startPoint3d);//圆心与第一个点构成向量 //Vector3d ce = conter.GetVectorTo(endPoint3d);//圆心与第二个点构成向量 //Vector3d xVector = new Vector3d(1, 0, 0);//X正方向的向量 ////获取角度 //double startAngle = cs.Y>0 ? xVector.GetAngleTo(cs): -xVector.GetAngleTo(cs);//圆心与第一个点的角度 //double endAngle = ce.Y>0 ? xVector.GetAngleTo(ce): -xVector.GetAngleTo(ce);//圆心与第二个点的角度 //获取角度 double startAngle = conter.GetAngle(startPoint3d); double endAngle = conter.GetAngle(endPoint3d); //创建圆弧对象 Arc arc = new Arc(conter, radius, startAngle, endAngle); return(AddEntityToModelSpace(db, arc));//添加到图形数据库中 }
public static CircularArc3d ConvertToCircularArc(this Arc arc) { Vector3d vector = arc.StartPoint - arc.Center; CircularArc3d arc3d = new CircularArc3d(arc.Center, arc.Normal, vector.Normalize(), arc.Radius, 0d, arc.EndAngle - arc.StartAngle); return(arc3d); }
/// <summary> /// Returns the tangents between the active CircularArc3d instance complete circle and a point. /// </summary> /// <remarks> /// Tangents start points are on the object to which this method applies, end points on the point passed as argument. /// Tangents are always returned in the same order: the tangent on the left side of the line from the circular arc center /// to the point before the one on the right side. /// </remarks> /// <param name="arc">The instance to which this method applies.</param> /// <param name="pt">The Point3d to which tangents are searched</param> /// <returns>An array of LineSegement3d representing the tangents (2) or null if there is none.</returns> /// <exception cref="Autodesk.AutoCAD.Runtime.Exception"> /// eNonCoplanarGeometry is thrown if the objects do not lies on the same plane.</exception> public static LineSegment3d[]? GetTangentsTo([NotNull] this CircularArc3d arc, Point3d pt) { // check if arc and point lies on the plane var normal = arc.Normal; var WCS2OCS = Matrix3d.WorldToPlane(normal); var elevation = arc.Center.TransformBy(WCS2OCS).Z; if (Math.Abs(elevation - pt.TransformBy(WCS2OCS).Z) < Tolerance.Global.EqualPoint) { throw new Autodesk.AutoCAD.Runtime.Exception( Autodesk.AutoCAD.Runtime.ErrorStatus.NonCoplanarGeometry); } var plane = new Plane(Point3d.Origin, normal); var ca2d = new CircularArc2d(arc.Center.Convert2d(plane), arc.Radius); var lines2d = ca2d.GetTangentsTo(pt.Convert2d(plane)); if (lines2d == null) { return(null); } var result = new LineSegment3d[lines2d.Length]; for (var i = 0; i < lines2d.Length; i++) { var ls2d = lines2d[i]; result[i] = new LineSegment3d(ls2d.StartPoint.Convert3d(normal, elevation), ls2d.EndPoint.Convert3d(normal, elevation)); } return(result); }
public static IEnumerable <IntersectionInfo> IntersectArcs(Arc source, ExtendType?coerceSourceExtendType, Arc target, ExtendType?coerceTargetExtendType) { var points = new Point3dCollection(); source.IntersectWith(target, Intersect.ExtendBoth, points, IntPtr.Zero, IntPtr.Zero); if (points.Count <= 0) { return(new IntersectionInfo[0]); } // NOTE: Use Arc's GetParameterAtPoint will throw exception if the intersect point is // on the Arc's extension, but CircularArc3d.GetParameterOf is available, so I convert // the Arc to CircularArc3d here. var sourceArc = new CircularArc3d(source.Center, source.Normal, source.Normal.GetPerpendicularVector(), source.Radius, source.StartAngle, source.EndAngle); var targetArc = new CircularArc3d(target.Center, target.Normal, target.Normal.GetPerpendicularVector(), target.Radius, target.StartAngle, target.EndAngle); var result = new List <IntersectionInfo>(); foreach (Point3d point in points) { var sourceParam = sourceArc.GetParameterOf(point); var sourceExtendType = ParamToExtendTypeForArc(sourceArc, sourceParam, coerceSourceExtendType); var targetParam = targetArc.GetParameterOf(point); var targetExtendType = ParamToExtendTypeForArc(targetArc, targetParam, coerceTargetExtendType); } return(result); }
/// <summary> /// Returns the tangents between the active CircularArc3d instance complete circle and another one. /// </summary> /// <remarks> /// Tangents start points are on the object to which this method applies, end points on the one passed as argument. /// Tangents are always returned in the same order: outer tangents before inner tangents, and for both, /// the tangent on the left side of the line from this circular arc center to the other one before the one on the right side. /// </remarks> /// <param name="arc">The instance to which this method applies.</param> /// <param name="other">The CircularArc3d to which searched for tangents.</param> /// <param name="flags">An enum value specifying which type of tangent is returned.</param> /// <returns>An array of LineSegment3d representing the tangents (maybe 2 or 4) or null if there is none.</returns> /// <exception cref="Autodesk.AutoCAD.Runtime.Exception"> /// eNonCoplanarGeometry is thrown if the objects do not lies on the same plane.</exception> public static LineSegment3d[] GetTangentsTo(this CircularArc3d arc, CircularArc3d other, TangentType flags) { // check if circles lies on the same plane Vector3d normal = arc.Normal; Matrix3d WCS2OCS = Matrix3d.WorldToPlane(normal); double elevation = arc.Center.TransformBy(WCS2OCS).Z; if (!(normal.IsParallelTo(other.Normal) && Math.Abs(elevation - other.Center.TransformBy(WCS2OCS).Z) < Tolerance.Global.EqualPoint)) { throw new Autodesk.AutoCAD.Runtime.Exception( Autodesk.AutoCAD.Runtime.ErrorStatus.NonCoplanarGeometry); } Plane plane = new Plane(Point3d.Origin, normal); Matrix3d OCS2WCS = Matrix3d.PlaneToWorld(plane); CircularArc2d ca2d1 = new CircularArc2d(arc.Center.Convert2d(plane), arc.Radius); CircularArc2d ca2d2 = new CircularArc2d(other.Center.Convert2d(plane), other.Radius); LineSegment2d[] lines2d = ca2d1.GetTangentsTo(ca2d2, flags); if (lines2d == null) { return(null); } LineSegment3d[] result = new LineSegment3d[lines2d.Length]; for (int i = 0; i < lines2d.Length; i++) { LineSegment2d ls2d = lines2d[i]; result[i] = new LineSegment3d(ls2d.StartPoint.Convert3d(normal, elevation), ls2d.EndPoint.Convert3d(normal, elevation)); } return(result); }
/// <summary> /// Returns the tangents between the active CircularArc3d instance complete circle and a point. /// </summary> /// <remarks> /// Tangents start points are on the object to which this method applies, end points on the point passed as argument. /// Tangents are always returned in the same order: the tangent on the left side of the line from the circular arc /// center /// to the point before the one on the right side. /// </remarks> /// <param name="arc">The instance to which this method applies.</param> /// <param name="pt">The Point3d to which tangents are searched</param> /// <returns>An array of LineSegement3d representing the tangents (2) or null if there is none.</returns> /// <exception cref="Autodesk.AutoCAD.Runtime.Exception"> /// eNonCoplanarGeometry is thrown if the objects do not lies on the same plane. /// </exception> public static LineSegment3d[] GetTangentsTo(this CircularArc3d arc, Point3d pt) { // check if arc and point lies on the plane var normal = arc.Normal; var wcs2Ocs = Matrix3d.WorldToPlane(normal); var elevation = arc.Center.TransformBy(wcs2Ocs).Z; if (Math.Abs(elevation - pt.TransformBy(wcs2Ocs).Z) < Tolerance.Global.EqualPoint) { throw new Exception( ErrorStatus.NonCoplanarGeometry); } var plane = new Plane(Point3d.Origin, normal); _ = Matrix3d.PlaneToWorld(plane); var ca2D = new CircularArc2d(arc.Center.Convert2d(plane), arc.Radius); var lines2D = ca2D.GetTangentsTo(pt.Convert2d(plane)); if (lines2D == null) { return(null); } var result = new LineSegment3d[lines2D.Length]; for (var i = 0; i < lines2D.Length; i++) { var ls2D = lines2D[i]; result[i] = new LineSegment3d(ls2D.StartPoint.Convert3D(normal, elevation), ls2D.EndPoint.Convert3D(normal, elevation)); } return(result); }
/// <summary>Создание дуг</summary> private void CreateArcs(XElement root, Transaction tr, BlockTableRecord btr) { foreach (XElement curveXelement in root.Elements("Arc")) { XElement startPointXElement = curveXelement.Element("StartPoint"); Point3d startPoint = startPointXElement.GetAsPoint(); XElement endPointXElement = curveXelement.Element("EndPoint"); Point3d endPoint = endPointXElement.GetAsPoint(); XElement pointOnArcXElement = curveXelement.Element("PointOnArc"); Point3d pointOnArc = pointOnArcXElement.GetAsPoint(); // create a CircularArc3d CircularArc3d carc = new CircularArc3d(startPoint, pointOnArc, endPoint); // now convert the CircularArc3d to an Arc Point3d cpt = carc.Center; Vector3d normal = carc.Normal; Vector3d refVec = carc.ReferenceVector; Plane plan = new Plane(cpt, normal); double ang = refVec.AngleOnPlane(plan); using (Arc arc = new Arc(cpt, normal, carc.Radius, carc.StartAngle + ang, carc.EndAngle + ang)) { btr.AppendEntity(arc); tr.AddNewlyCreatedDBObject(arc, true); } // dispose CircularArc3d carc.Dispose(); } }
/// <summary> /// Returns the tangents between the active CircularArc3d instance complete circle and another one. /// </summary> /// <remarks> /// Tangents start points are on the object to which this method applies, end points on the one passed as argument. /// Tangents are always returned in the same order: outer tangents before inner tangents, and for both, /// the tangent on the left side of the line from this circular arc center to the other one before the one on the right side. /// </remarks> /// <param name="arc">The instance to which this method applies.</param> /// <param name="other">The CircularArc3d to which searched for tangents.</param> /// <param name="flags">An enum value specifying which type of tangent is returned.</param> /// <returns>An array of LineSegment3d representing the tangents (maybe 2 or 4) or null if there is none.</returns> /// <exception cref="Autodesk.AutoCAD.Runtime.Exception"> /// eNonCoplanarGeometry is thrown if the objects do not lies on the same plane.</exception> public static LineSegment3d[] GetTangentsTo(this CircularArc3d arc, CircularArc3d other, TangentType flags) { // check if circles lies on the same plane Vector3d normal = arc.Normal; Matrix3d WCS2OCS = Matrix3d.WorldToPlane(normal); double elevation = arc.Center.TransformBy(WCS2OCS).Z; if (!(normal.IsParallelTo(other.Normal) && Math.Abs(elevation - other.Center.TransformBy(WCS2OCS).Z) < Tolerance.Global.EqualPoint)) throw new Autodesk.AutoCAD.Runtime.Exception( Autodesk.AutoCAD.Runtime.ErrorStatus.NonCoplanarGeometry); Plane plane = new Plane(Point3d.Origin, normal); Matrix3d OCS2WCS = Matrix3d.PlaneToWorld(plane); CircularArc2d ca2d1 = new CircularArc2d(arc.Center.Convert2d(plane), arc.Radius); CircularArc2d ca2d2 = new CircularArc2d(other.Center.Convert2d(plane), other.Radius); LineSegment2d[] lines2d = ca2d1.GetTangentsTo(ca2d2, flags); if (lines2d == null) return null; LineSegment3d[] result = new LineSegment3d[lines2d.Length]; for (int i = 0; i < lines2d.Length; i++) { LineSegment2d ls2d = lines2d[i]; result[i] = new LineSegment3d(ls2d.StartPoint.Convert3d(normal, elevation), ls2d.EndPoint.Convert3d(normal, elevation)); } return result; }
public static IEnumerable <IntersectionInfo> IntersectLineArc(Line line, Arc arc, ExtendType?coerceArcExtendType) { var points = new Point3dCollection(); line.IntersectWith(arc, Intersect.ExtendBoth, points, IntPtr.Zero, IntPtr.Zero); if (points.Count <= 0) { return(new IntersectionInfo[0]); } // NOTE: Use Line's GetParameterAtPoint will throw exception if the intersect point is // on the line's extension, but LineSegment3d.GetParameterOf is available, so I convert // the Line to LineSegment3d here. var lineSegment = new LineSegment3d(line.StartPoint, line.EndPoint); var circularArc = new CircularArc3d(arc.Center, arc.Normal, arc.Normal.GetPerpendicularVector(), arc.Radius, arc.StartAngle, arc.EndAngle); var result = new List <IntersectionInfo>(); foreach (Point3d point in points) { var lineParam = lineSegment.GetParameterOf(point); var lineExtendType = ParamToExtendTypeForLine(lineParam); var arcParam = circularArc.GetParameterOf(point); var arcExtendType = ParamToExtendTypeForArc(circularArc, arcParam, coerceArcExtendType); result.Add(new IntersectionInfo(lineExtendType, arcExtendType, point)); } return(result); }
public static ExtendType ParamToExtendTypeForArc(CircularArc3d arc, double param, ExtendType?coerceExtendType) { var startParam = arc.GetParameterOf(arc.StartPoint); var endParam = arc.GetParameterOf(arc.EndPoint); var result = ExtendType.None; // If param is in the middle of startParam and endParam var val = (param - startParam) * (param - endParam); if (val.SmallerOrEqual(0.0)) { result = ExtendType.None; } else { // If coerce extend type is not null. if (coerceExtendType != null) { result = coerceExtendType.Value; } else { // Determine which distance is shorter. if (Math.Abs(param - startParam) >= Math.Abs(param - endParam)) { result = ExtendType.ExtendEnd; } else { result = ExtendType.ExtendStart; } } } return(result); }
/// <summary> /// 三点画圆弧 /// </summary> /// <param name="db">数据库对象</param> /// <param name="startPoint">起点</param> /// <param name="pointOnArc">圆弧上一点</param> /// <param name="endPoint">终点</param> /// <returns></returns> public static ObjectId AddArcToModeSpace(this Database db, Point3d startPoint, Point3d pointOnArc, Point3d endPoint) { // 先判断是否在同一条直线上 if (startPoint.IsOnOneLine(pointOnArc, endPoint)) { return(ObjectId.Null); } // 创建几何对象 CircularArc3d cArc = new CircularArc3d(startPoint, pointOnArc, endPoint); // 通过几何对象获取其属性 double radius = cArc.Radius; //半径 /************************************** * Point3d center = cArc.Center; // 所在圆的圆心 * Vector3d cs = center.GetVectorTo(startPoint); // 圆心到起点的向量 * Vector3d ce = center.GetVectorTo(endPoint); // 圆心到终点的向量 * Vector3d xVector = new Vector3d(1, 0, 0); // x正方向的向量 * // 圆弧起始角度 * double startAngle = cs.Y > 0 ? xVector.GetAngleTo(cs) : -xVector.GetAngleTo(cs); * // 圆弧终止角度 * double endAngle = ce.Y > 0 ? xVector.GetAngleTo(ce) : -xVector.GetAngleTo(ce); ********************************************/ // 创建圆弧对象 Arc arc = new Arc(cArc.Center, cArc.Radius, cArc.Center.GetAngleToXAxis(startPoint), cArc.Center.GetAngleToXAxis(endPoint)); // 加入到图形数据库 return(db.AddEntityToModeSpace(arc)); }
public void DimRadiusArrowStyle() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; Arc arc = new Arc(); //初始化圆弧 using (Transaction trans = db.TransactionManager.StartTransaction()) //开始事务处理 { //1.选择圆弧 PromptEntityOptions arcOpt = new PromptEntityOptions("\n选择圆弧"); arcOpt.SetRejectMessage("请选择圆弧对象!"); arcOpt.AddAllowedClass(typeof(Arc), false); PromptEntityResult arcRes = ed.GetEntity(arcOpt); if (arcRes.Status != PromptStatus.OK) { return; } arc = arcRes.ObjectId.GetObject(OpenMode.ForRead) as Arc; CircularArc3d arc3d = new CircularArc3d(arc.StartPoint, arc.Center.PolarPoint((arc.StartAngle + arc.EndAngle) / 2, arc.Radius), arc.EndPoint); //2.设置标注比例 PromptDoubleOptions scaleOpt = new PromptDoubleOptions($"\n设置标注比例<{scale}>"); scaleOpt.AllowNegative = false; scaleOpt.AllowZero = false; scaleOpt.AllowNone = true; PromptDoubleResult scaleRes = ed.GetDouble(scaleOpt); if (scaleRes.Status == PromptStatus.OK) { scale = scaleRes.Value; } //3.绘制圆弧半径箭头标注 db.ArrowRadiusDim(arc3d, scale); trans.Commit();//执行事务处理 } }
private static Curve CreateEdge(double rad, Edge edge, bool createArc) { Curve c = null; if (createArc) { // Calculate a mid-point for our arc var vec = edge.End - edge.Start; var len = vec.Length; var vmid = edge.Start + (vec * 0.5); vec = vec.RotateBy(Math.PI * 0.5, Vector3d.ZAxis); vec = -0.1 * vec; var mid = vmid + vec; // Create the initial arc between the center points of the // two nodes, as well as circles around the nodes var ca = new CircularArc3d(edge.Start, mid, edge.End); var c1 = new CircularArc3d(edge.Start, Vector3d.ZAxis, rad); var c2 = new CircularArc3d(edge.End, Vector3d.ZAxis, rad); // Intersect the arc with the two circles var pts1 = ca.IntersectWith(c1); var pts2 = ca.IntersectWith(c2); // Adjust the start and end of the arc, effectively trimming // it to the circles var newStart = edge.Start; var newEnd = edge.End; if (pts1 != null && pts1.Length > 0) { newStart = pts1[0]; } if (pts2 != null && pts2.Length > 0) { newEnd = pts2[0]; } // Create our new, trimmed arc, and the database version of it var ca2 = new CircularArc3d(newStart, mid, newEnd); c = Arc.CreateFromGeCurve(ca2); } else { // Create the line - adjusted to go from the node circles) // and add it to the database var vec = edge.End - edge.Start; var unit = vec / vec.Length; c = new Line(edge.Start + unit * rad, edge.End - unit * rad); } return(c); }
public static Polyline ConvertToPolyline([NotNull] this CircularArc3d arc) { var poly = new Polyline(); poly.AddVertexAt(0, new Point2d(arc.StartPoint.X, arc.StartPoint.Y), GetBulge(arc), 0, 0); poly.AddVertexAt(1, new Point2d(arc.EndPoint.X, arc.EndPoint.Y), 0, 0, 0); return(poly); }
public static Arc ConvertToArc(this CircularArc3d arc3d) { double angle = arc3d.ReferenceVector.AngleOnPlane(new Plane(arc3d.Center, arc3d.Normal)); Arc arc = new Arc(arc3d.Center, arc3d.Normal, arc3d.Radius, arc3d.StartAngle + angle, arc3d.EndAngle + angle); return(arc); }
public CircularArc3d ArcToNative(Arc arc) { var _arc = new CircularArc3d(PointToNative(arc.startPoint), PointToNative(arc.midPoint), PointToNative(arc.endPoint)); _arc.SetAxes(VectorToNative(arc.plane.normal), VectorToNative(arc.plane.xdir)); _arc.SetAngles((double)arc.startAngle, (double)arc.endAngle); return(_arc); }
//This function gets the 5 points on the passed arc and adds those points //to passed point array (pointList) static public void BreakArc(ref Arc arc, ref Point3dCollection pointList) { CircularArc3d arcseg = new CircularArc3d(arc.Center, arc.Normal, arc.Normal.GetPerpendicularVector(), arc.Radius, arc.StartAngle, arc.EndAngle); var pointArray = arcseg.GetSamplePoints(5); bool bReverse = false; //Whether to bReverse the reading of points from line, this case is valid //only if this function is called for line segment of polyline. if (pointList.Count > 0) { Point3d currentPoint = pointList[pointList.Count - 1]; if (currentPoint != pointArray[0].Point) { bReverse = true; } } int nLength = pointArray.Length; int nIndex = 0; if (bReverse == false) { while (nIndex < nLength) { if (pointList.Contains(pointArray[nIndex].Point) == false) { pointList.Add(pointArray[nIndex].Point); DBPoint point = new DBPoint(pointArray[nIndex].Point); point.ColorIndex = 1; point.SetDatabaseDefaults(); TGpoints.Add(point); } nIndex++; } } else { nIndex = nLength; while (nIndex > 0) { nIndex = nIndex - 1; if (pointList.Contains(pointArray[nIndex].Point) == false) { pointList.Add(pointArray[nIndex].Point); DBPoint point = new DBPoint(pointArray[nIndex].Point); point.ColorIndex = 1; point.SetDatabaseDefaults(); TGpoints.Add(point); } } } }
public static double GetArcBulge(this CircularArc3d arc) { double deltaAng = arc.EndAngle - arc.StartAngle; if (deltaAng < 0) { deltaAng += 2 * Math.PI; } return(Math.Tan(deltaAng * 0.25)); }
private static Arc CreateFromCircularArc(CircularArc3d circArc) { Point3d center = circArc.Center; Vector3d normal = circArc.Normal; Vector3d referenceVector = circArc.ReferenceVector; Plane plane = new Plane(center, normal); double num = referenceVector.AngleOnPlane(plane); return(new Arc(center, normal, circArc.Radius, circArc.StartAngle + num, circArc.EndAngle + num)); }
public static Point3d?GetOrthoNormalPointEx(this Polyline pline, Point3d point) { point = point.OrthoProject(pline.GetPlane()); List <Point3d> res = new List <Point3d>(); var segments = pline.GetSegments(); foreach (var s in segments) { Vector3d vector = point - s.StartPoint; Vector3d segmVector = s.EndPoint - s.StartPoint; double cos = segmVector.GetCos2d(vector); double length = s.GetLength(s.GetParameterOf(s.StartPoint), s.GetParameterOf(s.EndPoint), Tolerance.Global.EqualPoint); if (cos >= 0d && cos * vector.Length <= segmVector.Length) { if (s is CircularArc3d) { CircularArc3d arc = (CircularArc3d)s; Vector3d central = point - arc.Center; PointOnCurve3d pointOn = null; try { pointOn = s.GetNormalPoint(point, Tolerance.Global); } catch (InvalidOperationException) { continue; } if (pointOn != null) { res.Add(pointOn.Point); } } else if (s is LineSegment3d) { LineSegment3d line = (LineSegment3d)s; Line buffer = new Line(line.StartPoint, line.EndPoint); res.Add(buffer.GetPointAtDist(cos * vector.Length)); } } } if (res.Count == 0) { return(null); } else { res.Sort((p1, p2) => Comparer <double> .Default.Compare((point - p1).Length, (point - p2).Length)); return(res[0]); } }
// Arc public Arc ArcToSpeckle(CircularArc3d arc) { var _arc = new Arc(PlaneToSpeckle(arc.GetPlane()), arc.Radius, arc.StartAngle, arc.EndAngle, Math.Abs(arc.EndAngle - arc.StartAngle), ModelUnits); _arc.startPoint = PointToSpeckle(arc.StartPoint); _arc.endPoint = PointToSpeckle(arc.EndPoint); _arc.domain = IntervalToSpeckle(arc.GetInterval()); _arc.length = arc.GetLength(arc.GetParameterOf(arc.StartPoint), arc.GetParameterOf(arc.EndPoint), tolerance); _arc.bbox = BoxToSpeckle(arc.OrthoBoundBlock); return(_arc); }
public static DTO.ArcPayload ToArcPayload(this CircularArc3d arc) { //Whilst AutoCAD has a number of angle display formats, the actual angle unit is the radian. //Choose the x-axis such that it lies along the line connecting the center of the arc to it's start point (A). //This way start angle is always 0 as Speckle connectors expect. var xAxis = Normalize(arc.Center.GetVectorTo(arc.StartPoint)); //Rotate point A by 90 degrees about z to get a point on the y-axis var pointB = arc.StartPoint.RotateBy(90 * System.Math.PI / 180, arc.Normal, arc.Center); var yAxis = Normalize(arc.Center.GetVectorTo(pointB)); var arcNormal = Normalize(arc.Normal); var normalPayload = new DTO.VectorPayload { Value = new List <double> { arcNormal.X, arcNormal.Y, arcNormal.Z } }; var planePayload = new DTO.PlanePayload { Normal = normalPayload, Origin = new DTO.PointPayload { Value = new List <double> { arc.Center.X, arc.Center.Y, arc.Center.Z } }, XDir = new DTO.VectorPayload { Value = new List <double> { xAxis.X, xAxis.Y, xAxis.Z } }, YDir = new DTO.VectorPayload { Value = new List <double> { yAxis.X, yAxis.Y, yAxis.Z } }, }; var sweep = GetSweep(arc.StartAngle, arc.EndAngle); var arcPayload = new DTO.ArcPayload() { Plane = planePayload, Radius = arc.Radius, StartAngle = 0, EndAngle = sweep, //EndAngle is also the sweep because start angle is always 0 AngleRadians = sweep }; return(arcPayload); }
private static Entity DrawCircularArc(CircularArc arc, double defaultElevation, Point[] densifiedPoints) { PointN pointN = arc.FromPoint as PointN; PointN pointN2 = arc.ToPoint as PointN; PointN pointN3 = arc.CenterPoint as PointN; Point3d point3d = new Point3d(pointN.X, pointN.Y, pointN.Z); Point3d point3d2 = new Point3d(pointN3.X, pointN3.Y, pointN3.Z); Point3d point3d3 = new Point3d(pointN2.X, pointN2.Y, pointN2.Z); Point2d centerPoint = new Point2d(pointN3.X, pointN3.Y); Point2d point2d = new Point2d(pointN.X, pointN.Y); Math.Abs(centerPoint.GetDistanceTo(point2d)); CircularArc3d circArc; if (densifiedPoints != null) { int num = densifiedPoints.Length / 2; PointN pointN4 = (PointN)densifiedPoints[num]; if (arc.IsCounterClockwise) { PointN arg_CC_0 = (PointN)densifiedPoints[0]; PointN arg_D9_0 = (PointN)densifiedPoints[densifiedPoints.Length - 1]; } else { PointN arg_E4_0 = (PointN)densifiedPoints[0]; PointN arg_F1_0 = (PointN)densifiedPoints[densifiedPoints.Length - 1]; } Point3d point3d4 = new Point3d(pointN4.X, pointN4.Y, pointN4.Z); circArc = new CircularArc3d(point3d, point3d4, point3d3); } else { Point2d point2d2 = new Point2d(point3d.X, point3d.Y); Point2d point2d3 = new Point2d(point3d3.X, point3d3.Y); double num2 = GIS2CAD.CalcThetaFromVectors(point2d2, point2d3, centerPoint, arc.IsCounterClockwise); double num3 = Math.Tan(num2 / 4.0); if (!arc.IsCounterClockwise) { num3 *= -1.0; } CircularArc2d circularArc2d = new CircularArc2d(point2d2, point2d3, num3, false); Point2d[] samplePoints = circularArc2d.GetSamplePoints(3); Point3d point3d5 = new Point3d(samplePoints[1].X, samplePoints[1].Y, point3d2.Z); circArc = new CircularArc3d(point3d, point3d5, point3d3); } new Point3d(pointN3.X, pointN3.Y, pointN3.Z); Arc arc2 = GIS2CAD.CreateFromCircularArc(circArc); arc2.ColorIndex = (256); return(arc2); }
/// <summary> /// 三点绘制圆 /// </summary> /// <param name="db"></param> /// <param name="point1"></param> /// <param name="point2"></param> /// <param name="point3"></param> /// <returns></returns> public static ObjectId AddCircleModeSpace(this Database db, Point3d point1, Point3d point2, Point3d point3) { // 先判断三点是否在同一直线上 if (point1.IsOnOneLine(point2, point3)) { return(ObjectId.Null); } // 声明几何类Circular3d对象 CircularArc3d cArc = new CircularArc3d(point1, point2, point3); return(db.AddCircleModeSpace(cArc.Center, cArc.Radius)); }
public CircularArc3d GetArcSegmentAt(int index) { if (base.isInstanced()) { CircularArc3d GetArcSegmentAt = BasePolyline.GetArcSegmentAt(index); tr.Dispose(); return(GetArcSegmentAt); } else { return(BasePolyline.GetArcSegmentAt(index)); } }
//根据三点创建圆弧 public static void CreateArc(this Arc arc, Point3d startPoint, Point3d pointOnArc, Point3d endPoint) { //创建一个几何类的圆弧对象 CircularArc3d geArc = new CircularArc3d(startPoint, pointOnArc, endPoint); //将几何类圆弧对象的圆心和半径赋值给圆弧 Point3d centerPoint = geArc.Center; arc.Center = centerPoint; arc.Radius = geArc.Radius; //计算起始和终止角度 arc.StartAngle = startPoint.AngleFromXAxis(centerPoint); arc.EndAngle = endPoint.AngleFromXAxis(centerPoint); }
/// <summary> /// 三点绘制圆 /// </summary> /// <param name="db">图形数据库</param> /// <param name="point1">第一个点</param> /// <param name="point2">第二个点</param> /// <param name="point3">第三个点</param> /// <returns>对象Id</returns> public static ObjectId AddCircleToModelSpace(this Database db, Point3d point1, Point3d point2, Point3d point3) { //判断三点是否在同一条直线上 if (point1.IsOnOneLine(point2, point3)) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("3个顶点在一条直线上,无法绘制圆"); return(ObjectId.Null); } //创建几何类CircularArc3d对象 CircularArc3d CArc = new CircularArc3d(point1, point2, point3); return(AddCircleToModelSpace(db, CArc.Center, CArc.Radius)); }
Coordinate[] GetTessellatedCurveCoordinates(CircularArc3d curve) { var coordinateList = new CoordinateList(); if (curve.StartPoint != curve.EndPoint) { switch (this.CurveTessellationMethod) { case CurveTessellation.None: coordinateList.Add(this.ReadCoordinate(curve.StartPoint)); coordinateList.Add(this.ReadCoordinate(curve.EndPoint)); break; case CurveTessellation.Linear: { var samplePoints = curve.GetSamplePoints((int)Math.Round(this.CurveTessellationValue)); for (int i = 0; i < samplePoints.Length; i++) { Point3d point3D = samplePoints[i].Point; coordinateList.Add(this.ReadCoordinate(point3D)); } break; } case CurveTessellation.Scaled: { double num = curve.GetArea(curve.GetParameterOf(curve.StartPoint), curve.GetParameterOf(curve.EndPoint)) * this.CurveTessellationValue; double num2 = Math.Acos((curve.Radius - 1.0 / (num / 2.0)) / curve.Radius); int num3 = (int)Math.Round(6.2831853071795862 / num2); if (num3 < 8) { num3 = 8; } if (num3 > 128) { num3 = 128; } var samplePoints2 = curve.GetSamplePoints(num3); for (int j = 0; j < samplePoints2.Length; j++) { var point3d2 = samplePoints2[j].Point; coordinateList.Add(this.ReadCoordinate(point3d2)); } break; } } } return(coordinateList.ToCoordinateArray()); }
public static Arc CreateArcFromRadius(this Editor acCurEd, Point3d startPoint, Point3d endPoint, double radius) { Arc arc = null; var ucsMat = acCurEd.CurrentUserCoordinateSystem; var vNormal = ucsMat.CoordinateSystem3d.Zaxis; var pStart = startPoint.TransformBy(ucsMat); // Start point in WCS var pEnd = endPoint.TransformBy(ucsMat); // End point in WCS // Finding center point of arc. var circ1 = new CircularArc3d(pStart, vNormal, radius); var circ2 = new CircularArc3d(pEnd, vNormal, radius); var pts = circ1.IntersectWith(circ2); circ1.Dispose(); circ2.Dispose(); try { if (pts.Length < 1) { return(null); } } catch (Exception) { return(null); } var pCenter = pts[0]; Vector3d v1 = pStart - pCenter, v2 = pEnd - pCenter; if (v1.CrossProduct(v2).DotProduct(vNormal) < 0) { pCenter = pts[1]; } var cCirc = new CircularArc3d(pCenter, vNormal, radius); var parStart = cCirc.GetParameterOf(pStart); var parEnd = cCirc.GetParameterOf(pEnd); var parMid = (parStart + parEnd) * 0.5; var pMid = cCirc.EvaluatePoint(parMid); cCirc.Dispose(); var cArc = new CircularArc3d(pStart, pMid, pEnd); var angle = cArc.ReferenceVector.AngleOnPlane(new Plane(cArc.Center, cArc.Normal)); arc = new Arc(cArc.Center, cArc.Normal, cArc.Radius, cArc.StartAngle + angle, cArc.EndAngle + angle); cArc.Dispose(); return(arc); }
/// <summary> /// 由三点(Point3d)创建圆 /// </summary> /// <param name="pt1">点1</param> /// <param name="pt2">点2</param> /// <param name="pt3">点3</param> /// <returns>过三点的圆</returns> public static Circle Circle(Point3d pt1, Point3d pt2, Point3d pt3) { Vector3d va = pt1.GetVectorTo(pt2); Vector3d vb = pt1.GetVectorTo(pt3); if (va.GetAngleTo(vb) == 0 | va.GetAngleTo(vb) == Math.PI) { return(new Circle()); } CircularArc3d geoArc = new CircularArc3d(pt1, pt2, pt3); Point3d cenPt = new Point3d(geoArc.Center.X, geoArc.Center.Y, 0); double radius = geoArc.Radius; return(new Circle(cenPt, Vector3d.ZAxis, radius)); }
public void DimLength() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction trans = db.TransactionManager.StartTransaction()) { //1.选择直线或圆弧 PromptEntityOptions curveOpt = new PromptEntityOptions("\n选择直线或圆弧"); curveOpt.SetRejectMessage("请选择直线或圆弧对象!"); curveOpt.AddAllowedClass(typeof(Line), false); curveOpt.AddAllowedClass(typeof(Arc), false); PromptEntityResult curveRes = ed.GetEntity(curveOpt); if (curveRes.Status != PromptStatus.OK) { return; } Entity ent = curveRes.ObjectId.GetObject(OpenMode.ForRead) as Entity; //2.设置标注比例 PromptDoubleOptions scaleOpt = new PromptDoubleOptions($"\n设置标注比例<{scale}>"); scaleOpt.AllowNegative = false; scaleOpt.AllowZero = false; scaleOpt.AllowNone = true; PromptDoubleResult scaleRes = ed.GetDouble(scaleOpt); if (scaleRes.Status == PromptStatus.OK) { scale = scaleRes.Value; } //3.对直线和圆弧分别进行标注 if (ent is Line)//如果为直线 { Line line = ent as Line; LineSegment3d line3d = new LineSegment3d(line.StartPoint, line.EndPoint); db.LineLengthDim(line3d, scale); } else if (ent is Arc)//如果为圆弧 { Arc arc = ent as Arc; CircularArc3d arc3d = new CircularArc3d(arc.StartPoint, arc.Center.PolarPoint((arc.StartAngle + arc.EndAngle) / 2, arc.Radius), arc.EndPoint); db.ArcLengthDim(arc3d, scale); } trans.Commit(); } }
public static void Create(Grevit.Types.Wall w) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; DictionaryWallStyle ws = new DictionaryWallStyle(db); try { Wall wall = new Wall(); LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); bool newEnt = false; if (Command.existing_objects.ContainsKey(w.GID)) wall = (Wall)tr.GetObject(Command.existing_objects[w.GID], OpenMode.ForWrite); else { wall.SetDatabaseDefaults(db); wall.SetToStandard(db); newEnt = true; wall.JustificationType = WallJustificationType.Center; } if (w.TypeOrLayer != "") { if (lt.Has(w.TypeOrLayer)) wall.LayerId = lt[w.TypeOrLayer]; } if (ws.Has(w.FamilyOrStyle, tr)) wall.StyleId = ws.GetAt(w.FamilyOrStyle); if (w.from != null && w.to != null) { wall.Set(GrevitPtoPoint3d(w.from), GrevitPtoPoint3d(w.to), Vector3d.ZAxis); } else { if (w.curve.GetType() == typeof(Grevit.Types.PLine)) { Grevit.Types.PLine pline = (Grevit.Types.PLine)w.curve; for (int i = 0; i < pline.points.Count; i++) { if (i == pline.points.Count - 1) { if (pline.closed) { w.from = pline.points[i]; w.to = pline.points[0]; Create(w); } } else { w.from = pline.points[i]; w.to = pline.points[i + 1]; Create(w); } } } else if (w.curve.GetType() == typeof(Grevit.Types.Line)) { Grevit.Types.Line baseline = (Grevit.Types.Line)w.curve; wall.Set(GrevitPtoPoint3d(baseline.from), GrevitPtoPoint3d(baseline.to), Vector3d.ZAxis); } else if (w.curve.GetType() == typeof(Grevit.Types.Arc)) { Grevit.Types.Arc baseline = (Grevit.Types.Arc)w.curve; CircularArc3d arc = new CircularArc3d(GrevitPtoPoint3d(baseline.center), Vector3d.ZAxis, Vector3d.ZAxis, baseline.radius, baseline.start, baseline.end); wall.Set(arc, Vector3d.ZAxis); } else if (w.curve.GetType() == typeof(Grevit.Types.Curve3Points)) { Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)w.curve; wall.Set(GrevitPtoPoint3d(baseline.a), GrevitPtoPoint3d(baseline.b), GrevitPtoPoint3d(baseline.c), Vector3d.ZAxis); } } wall.BaseHeight = w.height; if (newEnt) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); AddXData(w, wall); ms.AppendEntity(wall); tr.AddNewlyCreatedDBObject(wall, true); storeID(w, wall.Id); } writeProperties(wall, w.parameters, tr); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ed.WriteMessage(e.Message); tr.Abort(); } finally { tr.Dispose(); } }
public static DBObject Create(this Grevit.Types.Wall w, Transaction tr, Grevit.Types.Point from = null, Grevit.Types.Point to = null) { DictionaryWallStyle ws = new DictionaryWallStyle(Command.Database); try { if (from == null && to == null && w.curve.GetType() == typeof(Grevit.Types.PLine)) { Grevit.Types.PLine pline = (Grevit.Types.PLine)w.curve; for (int i = 0; i < pline.points.Count; i++) { if (i == pline.points.Count - 1) { if (pline.closed) { w.Create(tr, pline.points[i], pline.points[0]); } } else { w.Create(tr, pline.points[i], pline.points[i + 1]); } } } else { Wall wall = new Wall(); LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead); bool newEnt = false; if (Command.existing_objects.ContainsKey(w.GID)) wall = (Wall)tr.GetObject(Command.existing_objects[w.GID], OpenMode.ForWrite); else { wall.SetDatabaseDefaults(Command.Database); wall.SetToStandard(Command.Database); newEnt = true; wall.JustificationType = WallJustificationType.Center; } if (w.TypeOrLayer != "") { if (lt.Has(w.TypeOrLayer)) wall.LayerId = lt[w.TypeOrLayer]; } if (ws.Has(w.FamilyOrStyle, tr)) wall.StyleId = ws.GetAt(w.FamilyOrStyle); if (from != null && to != null) { wall.Set(from.ToPoint3d(), to.ToPoint3d(), Vector3d.ZAxis); } else { if (w.curve.GetType() == typeof(Grevit.Types.Line)) { Grevit.Types.Line baseline = (Grevit.Types.Line)w.curve; wall.Set(baseline.from.ToPoint3d(), baseline.to.ToPoint3d(), Vector3d.ZAxis); } else if (w.curve.GetType() == typeof(Grevit.Types.Arc)) { Grevit.Types.Arc baseline = (Grevit.Types.Arc)w.curve; CircularArc3d arc = new CircularArc3d(baseline.center.ToPoint3d(), Vector3d.ZAxis, Vector3d.ZAxis, baseline.radius, baseline.start, baseline.end); wall.Set(arc, Vector3d.ZAxis); } else if (w.curve.GetType() == typeof(Grevit.Types.Curve3Points)) { Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)w.curve; wall.Set(baseline.a.ToPoint3d(), baseline.b.ToPoint3d(), baseline.c.ToPoint3d(), Vector3d.ZAxis); } } wall.BaseHeight = w.height; if (newEnt) { BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); ms.AppendEntity(wall); tr.AddNewlyCreatedDBObject(wall, true); } return wall; } } catch (Autodesk.AutoCAD.Runtime.Exception e) { } return null; }