/// <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 Vector3d normal = arc.Normal; Matrix3d WCS2OCS = Matrix3d.WorldToPlane(normal); double 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); Plane plane = new Plane(Point3d.Origin, normal); Matrix3d OCS2WCS = Matrix3d.PlaneToWorld(plane); CircularArc2d ca2d = new CircularArc2d(arc.Center.Convert2d(plane), arc.Radius); LineSegment2d[] lines2d = ca2d.GetTangentsTo(pt.Convert2d(plane)); 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; }
private Line getLine(LineSegment3d segment, Curve curve) { Vector3d vectorIsoline = segment.Direction.GetPerpendicularVector() * Commands.Options.DashLength; if (IsNegate) { vectorIsoline = vectorIsoline.Negate(); } Point3d ptEndIsoline = segment.MidPoint + vectorIsoline; Line line = new Line(segment.MidPoint, ptEndIsoline); line.Layer = curve.Layer; line.LineWeight = curve.LineWeight; line.Color = curve.Color; line.Linetype = SymbolUtilityServices.LinetypeContinuousName; return line; }
public List<Line> GetLines(Curve curve) { List<Line> lines = new List<Line>(); if (curve is Polyline) { Polyline pl = (Polyline)curve; for (int i = 0; i < pl.NumberOfVertices; i++) { SegmentType segmentType = pl.GetSegmentType(i); if (segmentType == SegmentType.Line) { var lineSegment = pl.GetLineSegmentAt(i); var line = getLine(lineSegment, curve); lines.Add(line); } } } else if (curve is Line) { Line lineCurve = (Line)curve; LineSegment3d segment = new LineSegment3d(lineCurve.StartPoint, lineCurve.EndPoint); var line = getLine(segment, curve); lines.Add(line); } return lines; }
private double GetPolylineShape(LineSegment3d l1, LineSegment3d l2, Vector3d normal) { Vector3d v1 = l1.EndPoint - l1.StartPoint; Vector3d v2 = l2.EndPoint - l2.StartPoint; return v1.GetAngleTo(v2, normal); }
public static void Breakatpoint() { Document acDoc = acApp.DocumentManager.MdiActiveDocument; Database acDb = acDoc.Database; Editor acEd = acDoc.Editor; PromptSelectionResult psr = acEd.GetSelection(); if (psr.Status != PromptStatus.OK) { return; } foreach (ObjectId id in psr.Value.GetObjectIds()) { using (Transaction acTrans = acDb.TransactionManager.StartTransaction()) { BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acDb.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Line line = (Line)acTrans.GetObject(id, OpenMode.ForRead); PromptPointResult pr = acEd.GetPoint("Select break point"); if (pr.Status != PromptStatus.Cancel) { ObjectId objId; Point3d pointPr = pr.Value; //Test to ensure that point selected actually lies on the line if (IsPointOnCurve(line, pointPr)) { //create new line from selected line start point to point chosen var lineseg = new LineSegment3d(line.StartPoint, pointPr); var vec = lineseg.Direction.MultiplyBy(2).Negate(); Line line_seg1 = new Line(line.StartPoint, pointPr.Add(vec)); line_seg1.Layer = line.Layer; objId = acBlkTblRec.AppendEntity(line_seg1); acTrans.AddNewlyCreatedDBObject(line_seg1, true); //create new line from point chosen to end point on selected line lineseg = new LineSegment3d(pointPr, line.EndPoint); vec = lineseg.Direction.MultiplyBy(2).Negate(); Line line_seg2 = new Line(pointPr.Subtract(vec), line.EndPoint); line_seg2.Layer = line.Layer; objId = acBlkTblRec.AppendEntity(line_seg2); acTrans.AddNewlyCreatedDBObject(line_seg2, true); //remove origionally selected line Entity acEnt = acTrans.GetObject(id, OpenMode.ForWrite) as Entity; acEnt.Erase(); acEnt.Dispose(); } else { MessageBox.Show("Point chosen does not lie on the line selected"); } } else { return; } acTrans.Commit(); } } }