private static double CalcThetaFromVectors(Point2d fromPoint, Point2d endPoint, Point2d centerPoint, bool isCCW) { Vector2d vectorTo = centerPoint.GetVectorTo(fromPoint); Vector2d vectorTo2 = centerPoint.GetVectorTo(endPoint); double angleTo; if (isCCW) { angleTo = vectorTo2.GetAngleTo(vectorTo); } else { angleTo = vectorTo.GetAngleTo(vectorTo2); } Vector2d vectorTo3 = centerPoint.GetVectorTo(fromPoint); Vector2d vectorTo4 = centerPoint.GetVectorTo(endPoint); Vector3d vector3d = new Vector3d(vectorTo3.X, vectorTo3.Y, 0.0); Vector3d vector3d2 = new Vector3d(vectorTo4.X, vectorTo4.Y, 0.0); Vector3d vector3d3 = new Vector3d(0.0, 0.0, 1.0); if (isCCW) { angleTo = vector3d.GetAngleTo(vector3d2, vector3d3); } else { angleTo = vector3d2.GetAngleTo(vector3d, vector3d3); } return(angleTo); }
public static bool IsClockwise(this Arc arc) { var startPoint = new Point2d(arc.StartPoint.X, arc.StartPoint.Y); var centrePoint = new Point2d(arc.Center.X, arc.Center.Y); var endPoint = new Point2d(arc.EndPoint.X, arc.EndPoint.Y); var vecCentreStart = centrePoint.GetVectorTo(startPoint); var vecCentreEnd = centrePoint.GetVectorTo(endPoint); return(vecCentreStart.X * vecCentreEnd.Y - vecCentreStart.Y * vecCentreEnd.X < 0); }
public static bool IsClockwise(this Arc arc) { if (arc == null) { throw new ArgumentNullException(nameof(arc)); } var startPoint = new Point2d(arc.StartPoint.X, arc.StartPoint.Y); var centrePoint = new Point2d(arc.Center.X, arc.Center.Y); var endPoint = new Point2d(arc.EndPoint.X, arc.EndPoint.Y); var vecCentreStart = centrePoint.GetVectorTo(startPoint); var vecCentreEnd = centrePoint.GetVectorTo(endPoint); return(vecCentreStart.X * vecCentreEnd.Y - vecCentreStart.Y * vecCentreEnd.X < 0); }
public static Vector2d ToCadVector2d(PointN basePt, PointN destPt) { Point2d point2d = GIS2CAD.ToCadPoint2d(basePt); Point2d point2d2 = GIS2CAD.ToCadPoint2d(destPt); return(point2d.GetVectorTo(point2d2)); }
/// <summary> /// Method to get the midpoint between the current point and an input point /// </summary> /// <param name="pt1"></param> /// <param name="pt2"></param> /// <returns></returns> public static Point2d GetMidPoint(this Point2d pt1, Point2d pt2) { var vector = pt1.GetVectorTo(pt2); var halfwayPoint = pt1 + vector * 0.5; return(halfwayPoint); }
/// <summary> /// Returns the tangents between the active CircularArc2d 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 other one. /// </remarks> /// <param name="arc">The instance to which this method applies.</param> /// <param name="pt">The Point2d to which tangents are searched</param> /// <returns>An array of LineSegement2d representing the tangents (2) or null if there is none.</returns> public static LineSegment2d[] GetTangentsTo(this CircularArc2d arc, Point2d pt) { // check if the point is inside the circle Point2d center = arc.Center; if (pt.GetDistanceTo(center) <= arc.Radius) { return(null); } Vector2d vec = center.GetVectorTo(pt) / 2.0; CircularArc2d tmp = new CircularArc2d(center + vec, vec.Length); Point2d[] inters = arc.IntersectWith(tmp); if (inters == null) { return(null); } LineSegment2d[] result = new LineSegment2d[2]; Vector2d v1 = inters[0] - center; Vector2d v2 = inters[1] - center; int i = vec.X * v1.Y - vec.Y - v1.X > 0 ? 0 : 1; int j = i ^ 1; result[i] = new LineSegment2d(inters[0], pt); result[j] = new LineSegment2d(inters[1], pt); return(result); }
/// <summary> /// Gets the end point. /// </summary> /// <param name="geometry">The end point of the geometry.</param> /// <returns>The end point of the geometry</returns> public static Point2d GetEndPoint(this Line geometry, PanelMeasure size) { Point2d start = geometry.StartPoint.ToPoint2d(), end = geometry.EndPoint.ToPoint2d(); Double angle = start.GetVectorTo(end).Angle; Double distance = size.Frente.Real; return start.ToPoint2dByPolar(distance, angle); }
private static bool IsOffSetValidForSide(this Curve curve, Curve offSet, SidesOfCentre side) { if (offSet == null) { return(false); } var start = new Point2d(curve.StartPoint.X, curve.StartPoint.Y); var offSetVector = start.GetVectorTo(new Point2d(offSet.StartPoint.X, offSet.StartPoint.Y)); return(Math.Abs(curve.AngleFromCurveToForSide(side) - offSetVector.Angle) < RadiansHelper.ANGLE_TOLERANCE); }
// 由给定圆上三点创建圆的函数. public static ObjectId AddCircle(Point2d pt1, Point2d pt2, Point2d pt3) { const double pi = Math.PI; Vector2d va = pt1.GetVectorTo(pt2); Vector2d vb = pt1.GetVectorTo(pt3); if (va.GetAngleTo(vb) == 0 | va.GetAngleTo(vb) == pi) { ObjectId nullId = ObjectId.Null; return(nullId); } else { CircularArc2d geoArc = new CircularArc2d(pt1, pt2, pt3); Point3d cenPt = new Point3d(geoArc.Center.X, geoArc.Center.Y, 0); double radius = geoArc.Radius; Circle ent = new Circle(cenPt, Vector3d.ZAxis, radius); ObjectId entId = AppendEntity(ent); return(entId); } }
public static ObjectId AddCircle(Point2d pt1, Point2d pt2, Point2d pt3) { Vector2d vectorTo = pt1.GetVectorTo(pt2); Vector2d vectorTo2 = pt1.GetVectorTo(pt3); ObjectId result; if (vectorTo.GetAngleTo(vectorTo2) == 0.0 | vectorTo.GetAngleTo(vectorTo2) == 3.1415926535897931) { ObjectId @null = ObjectId.Null; result = @null; } else { CircularArc2d circularArc2d = new CircularArc2d(pt1, pt2, pt3); Point3d point3d; point3d..ctor(circularArc2d.Center.X, circularArc2d.Center.Y, 0.0); double radius = circularArc2d.Radius; Circle ent = new Circle(point3d, Vector3d.ZAxis, radius); ObjectId objectId = ModelSpace.AddEnt(ent); result = objectId; } return(result); }
public static double GetStairRotationAngle(Solid3d stair3d) { GripDataCollection grips = new GripDataCollection(); GetGripPointsFlags bitFlags = GetGripPointsFlags.GripPointsOnly; stair3d.GetGripPoints(grips, 0, 0, Application.DocumentManager.MdiActiveDocument.Editor.GetCurrentView().ViewDirection, bitFlags); // Grip point [0] is the start point of the polyline defining the stair // Grip point [0,1,2] are the points defining the vertical line and grip point [2,3,4] defining the horizontal line of the first step Point2d start = new Point2d(grips[2].GripPoint.X, grips[2].GripPoint.Y); Point2d end = new Point2d(grips[4].GripPoint.X, grips[4].GripPoint.Y); Point3d pInsert = grips[0].GripPoint; grips.Dispose(); return(start.GetVectorTo(end).Angle); }
public Ellipse InsertElipse() { Point2d pt1 = new Point2d(m_pts[0].X, m_pts[0].Y); Point2d pt2 = new Point2d(m_pts[1].X, m_pts[1].Y); //get the angle of the two points angleA = pt1.GetVectorTo(pt2).Angle; //creates our ellipse Ellipse el = new Ellipse(m_pts[0], Vector3d.ZAxis, new Vector3d(.0625, 0, 0), .71875, 0, 4.71238898); el.Layer = "DIM"; //rotate the ellipse to the same degree of our angleA el.TransformBy(Matrix3d.Rotation(angleA, Vector3d.ZAxis, m_pts[0])); return(el); }
protected Curve CreateOffset(double offsetDistance, Side side) { Transaction acTrans = _document.TransactionManager.TopTransaction; Curve baseEntity = acTrans.GetObject(this.BaseObject, OpenMode.ForRead) as Curve; Curve positiveOffset = baseEntity.GetOffsetCurves(offsetDistance)[0] as Curve; Curve negativeOffset = baseEntity.GetOffsetCurves(-offsetDistance)[0] as Curve; Point2d start = new Point2d(baseEntity.StartPoint.X, baseEntity.StartPoint.Y); var offSetVector = start.GetVectorTo(new Point2d(positiveOffset.StartPoint.X, positiveOffset.StartPoint.Y)); double offsetAngle; switch (side) { case Side.Left: offsetAngle = Rotation + Math.PI / 2; while (offsetAngle >= Math.PI * 2) { offsetAngle -= 2 * Math.PI; } break; case Side.Right: offsetAngle = Rotation - Math.PI / 2; while (offsetAngle < 0) { offsetAngle += 2 * Math.PI; } break; default: throw new ArgumentOutOfRangeException(nameof(side), "Invalid enum"); } if (Math.Abs(offsetAngle - offSetVector.Angle) < Tolerance.Global.GetAngle()) { return(positiveOffset); } else { return(negativeOffset); } }
public static double AngleFromCurveToForSide(this Curve curve, SidesOfCentre side) { double curveAngle; switch (curve) { case Line line: curveAngle = line.Angle; break; case Arc arc: var startPoint = new Point2d(arc.StartPoint.X, arc.StartPoint.Y); var arcCentre = new Point2d(arc.Center.X, arc.Center.Y); var startVector = arcCentre.GetVectorTo(startPoint); curveAngle = arc.Clockwise() ? startVector.Angle - RadiansHelper.DEGREES_90 : startVector.Angle + RadiansHelper.DEGREES_90; break; default: throw new ArgumentOutOfRangeException(nameof(curve), curve, null); } return(RadiansHelper.AngleForSide(curveAngle, side)); }
public static void Dim(LineSegment2d segment) { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Point2d p1 = segment.StartPoint; Point2d p2 = segment.EndPoint; //SetDimStyle(); TODO Fix Styles using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; using (RotatedDimension acRotDim = new RotatedDimension()) { const int n = 800; acRotDim.XLine1Point = new Point3d(p1.X, p1.Y, 0); acRotDim.XLine2Point = new Point3d(p2.X, p2.Y, 0); acRotDim.Rotation = p1.GetVectorTo(p2).Angle; Vector3d vector = acRotDim.XLine2Point.GetVectorTo(acRotDim.XLine1Point).GetNormal().MultiplyBy(n); acRotDim.DimLinePoint = acRotDim.XLine2Point.Add(vector.RotateBy(Math.PI / 2, new Vector3d(0, 0, 1))); if (acBlkTblRec != null) { acBlkTblRec.AppendEntity(acRotDim); } acTrans.AddNewlyCreatedDBObject(acRotDim, true); } acTrans.Commit(); } }
/// <summary> /// Initializes a new instance of the <see cref="Angle"/> class. /// </summary> /// <param name="start">The segment start point.</param> /// <param name="end">The segment end point.</param> public Angle(Point2d start, Point2d end) : this(start.GetVectorTo(end).Angle) { }
public static void dostuff(string strSourceBlockPath) { // Get the current document and database Document acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Point2d ClosestPoint = new Point2d(); LineSegment3d seg1 = new LineSegment3d(); ObjectId LayerOfBreakLine; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Pick the line/polyline for the block to reside on PromptEntityResult acSSPrompt1 = acDoc.Editor.GetEntity("Pick the line"); // If the prompt status is OK, objects were selected if (acSSPrompt1.Status == PromptStatus.OK) { ObjectId obj1 = acSSPrompt1.ObjectId; Entity ent1 = acTrans.GetObject(obj1, OpenMode.ForWrite) as Entity; LayerOfBreakLine = ent1.LayerId; switch (obj1.ObjectClass.DxfName) { case "LINE": Line ln1 = new Line(); ln1 = (Line)ent1; //get a 2d point that is actually on the line, not just close to where the user picked ClosestPoint = ln1.GetClosestPointTo(acSSPrompt1.PickedPoint, false).Add(ln1.StartPoint.GetAsVector()).Convert2d(ln1.GetPlane()); seg1 = new LineSegment3d(new Point3d(ln1.StartPoint.X, ln1.StartPoint.Y, ln1.StartPoint.Z), new Point3d(ln1.EndPoint.X, ln1.EndPoint.Y, ln1.EndPoint.Z)); break; case "LWPOLYLINE": Polyline pln1 = new Polyline(); pln1 = (Polyline)ent1; //loops through each segment of the polyline and finds which one our user selected point resides on for (int x = 0; x < pln1.NumberOfVertices; x++) { //converts a 3d point to 2d point that would be on the 2d polyline ClosestPoint = pln1.GetClosestPointTo(acSSPrompt1.PickedPoint, false).Add(pln1.StartPoint.GetAsVector()).Convert2d(pln1.GetPlane()); //then checks if that 2d point resides on the current segment being looked at if (pln1.OnSegmentAt(x, ClosestPoint, 0.00)) { seg1 = pln1.GetLineSegmentAt(x); break; } } break; } //get the angle of the two points //figure out how to freaking do this with a 3d point instead of converting to 2d //Line templine = new Line(seg1.StartPoint,seg1.EndPoint); //gets the start and endpoint of the segment selected Point2d pt1 = new Point2d(seg1.StartPoint.X, seg1.StartPoint.Y); Point2d pt2 = new Point2d(seg1.EndPoint.X, seg1.EndPoint.Y); //with those two points we can calculate the angle of the first segment double angle1 = pt1.GetVectorTo(pt2).Angle; double angle2 = pt2.GetVectorTo(pt1).Angle; try { //inserts the block and returns the extents of the block BEFORE it is rotate Extents3d ext = InsertBlockRef(new Point3d(ClosestPoint.X, ClosestPoint.Y, 0), strSourceBlockPath, angle1); //calculate the angle of the extent line Point2d extPoint1 = new Point2d(ext.MinPoint.X, ext.MinPoint.Y); Point2d extPoint2 = new Point2d(ext.MaxPoint.X, ext.MaxPoint.Y); double AngleofExtents = extPoint1.GetVectorTo(extPoint2).Angle; //double AngleofExtents = ext.MinPoint.Convert2d(templine.GetPlane()).GetVectorTo(ext.MaxPoint.Convert2d(templine.GetPlane())).Angle; double A = getDistanceBetweenTwoPoints(ext.MinPoint, ext.MaxPoint) / 2; //double width = A * Math.Cos(angle); //right angle thereom double B = A * Math.Cos(AngleofExtents); //using the centerpoint and the angle, calculate the vector of where to break the line segment Point3d point1 = new Point3d(ClosestPoint.X + B * Math.Cos(angle1), ClosestPoint.Y + B * Math.Sin(angle1), 0); Point3d point2 = new Point3d(ClosestPoint.X + B * Math.Cos(angle2), ClosestPoint.Y + B * Math.Sin(angle2), 0); BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord acBlkTbleRec; acBlkTbleRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; //ready to replace the original line/polyline with two new entities switch (obj1.ObjectClass.DxfName) { case "LINE": ent1.Erase(true); Line newline1 = new Line(new Point3d(seg1.StartPoint.X, seg1.StartPoint.Y, seg1.StartPoint.Z), point2); Line newline2 = new Line(point1, new Point3d(seg1.EndPoint.X, seg1.EndPoint.Y, seg1.EndPoint.Z)); newline1.LayerId = LayerOfBreakLine; newline2.LayerId = LayerOfBreakLine; acBlkTbleRec.AppendEntity(newline1); acBlkTbleRec.AppendEntity(newline2); acTrans.AddNewlyCreatedDBObject(newline1, true); acTrans.AddNewlyCreatedDBObject(newline2, true); break; case "LWPOLYLINE": Polyline oldpl = new Polyline(); oldpl = (Polyline)ent1; //create the first polyline on one side of the break Polyline newpl1 = new Polyline(); newpl1.LayerId = LayerOfBreakLine; for (int x = 0; seg1.EndPoint != oldpl.GetPoint3dAt(x); x++) { newpl1.AddVertexAt(x, oldpl.GetPoint2dAt(x), 0, 0, 0); } //add end point newpl1.AddVertexAt(newpl1.NumberOfVertices, new Point2d(point2.X, point2.Y), 0, 0, 0); //create the second polyline at the other side of the break Polyline newpl2 = new Polyline(); newpl2.LayerId = LayerOfBreakLine; int i = 0; //for tracking the index of our new polyline //start at the end of the old polyline and work our way backwards to the break point for (int x = oldpl.NumberOfVertices - 1; seg1.StartPoint != oldpl.GetPoint3dAt(x); x--) { newpl2.AddVertexAt(i, oldpl.GetPoint2dAt(x), 0, 0, 0); i++; } //add end point newpl2.AddVertexAt(i, new Point2d(point1.X, point1.Y), 0, 0, 0); //erases the old polyline and adds the new two polylines to the database ent1.Erase(true); acBlkTbleRec.AppendEntity(newpl1); acBlkTbleRec.AppendEntity(newpl2); acTrans.AddNewlyCreatedDBObject(newpl1, true); acTrans.AddNewlyCreatedDBObject(newpl2, true); break; } } catch (Exception e) { } } acTrans.Commit(); } }
public static void Break() { ObjectId LayerOfBreakLine; // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; LineSegment3d seg1 = new LineSegment3d(); LineSegment3d seg2 = new LineSegment3d(); // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Pick the line/polyline that will be broke PromptEntityResult acSSPrompt1 = acDoc.Editor.GetEntity("Pick the line to break"); // If the prompt status is OK, objects were selected if (acSSPrompt1.Status == PromptStatus.OK) { ObjectId obj1 = acSSPrompt1.ObjectId; Entity ent1 = acTrans.GetObject(obj1, OpenMode.ForWrite) as Entity; LayerOfBreakLine = ent1.LayerId; switch (obj1.ObjectClass.DxfName) { case "LINE": Line ln1 = new Line(); ln1 = (Line)ent1; seg1 = new LineSegment3d(new Point3d(ln1.StartPoint.X, ln1.StartPoint.Y, ln1.StartPoint.Z), new Point3d(ln1.EndPoint.X, ln1.EndPoint.Y, ln1.EndPoint.Z)); break; case "LWPOLYLINE": Polyline pln1 = new Polyline(); pln1 = (Polyline)ent1; //loops through each segment of the polyline and finds which one our user selected point resides on for (int x = 0; x < pln1.NumberOfVertices; x++) { //converts a 3d point to 2d point that would be on the 2d polyline Point2d temppt = pln1.GetClosestPointTo(acSSPrompt1.PickedPoint, false).Add(pln1.StartPoint.GetAsVector()).Convert2d(pln1.GetPlane()); //then checks if that 2d point resides on the current segment being looked at if (pln1.OnSegmentAt(x, temppt, 0.00)) { seg1 = pln1.GetLineSegmentAt(x); break; } } break; } // Pick the line/polyline that intersects with the line to be broke PromptEntityResult acSSPrompt2 = acDoc.Editor.GetEntity("Pick the intersecting line"); // If the prompt status is OK, objects were selected if (acSSPrompt2.Status == PromptStatus.OK) { ObjectId obj2 = acSSPrompt2.ObjectId; Entity ent2 = acTrans.GetObject(obj2, OpenMode.ForWrite) as Entity; switch (obj2.ObjectClass.DxfName) { case "LINE": Line ln2 = new Line(); ln2 = (Line)ent2; seg2 = new LineSegment3d(new Point3d(ln2.StartPoint.X, ln2.StartPoint.Y, ln2.StartPoint.Z), new Point3d(ln2.EndPoint.X, ln2.EndPoint.Y, ln2.EndPoint.Z)); break; case "LWPOLYLINE": Polyline pln2 = new Polyline(); pln2 = (Polyline)ent2; for (int x = 0; x < pln2.NumberOfVertices; x++) { Point2d temppt = pln2.GetClosestPointTo(acSSPrompt2.PickedPoint, false).Add(pln2.StartPoint.GetAsVector()).Convert2d(pln2.GetPlane()); if (pln2.OnSegmentAt(x, temppt, 0.00)) { seg2 = pln2.GetLineSegmentAt(x); break; } } break; } //checks if the line segments actually intersect //also checks if the line segment are the same //both cases would cause AutoCAD to crash if the code was allowed to run if (seg1.IntersectWith(seg2) != null || (seg1.Equals(seg2))) { //gets the start and endpoint of the segment selected Point2d pt1 = new Point2d(seg1.StartPoint.X, seg1.StartPoint.Y); Point2d pt2 = new Point2d(seg1.EndPoint.X, seg1.EndPoint.Y); //with those two points we can calculate the angle of the first segment double angle1 = pt1.GetVectorTo(pt2).Angle; double angle2 = pt2.GetVectorTo(pt1).Angle; //get the point where the two segments intersect Point3d[] intersectpoint = seg1.IntersectWith(seg2); Point3d center = intersectpoint[0]; //using the centerpoint and the angle, calculate the vector of where to break the line segment Point3d point1 = new Point3d(center.X + .125 * Math.Cos(angle1), center.Y + .125 * Math.Sin(angle1), 0); Point3d point2 = new Point3d(center.X + .125 * Math.Cos(angle2), center.Y + .125 * Math.Sin(angle2), 0); BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord acBlkTbleRec; acBlkTbleRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; //ready to replace the original line/polyline with two new entities switch (obj1.ObjectClass.DxfName) { case "LINE": ent1.Erase(true); Line newline1 = new Line(new Point3d(seg1.StartPoint.X, seg1.StartPoint.Y, seg1.StartPoint.Z), point2); Line newline2 = new Line(point1, new Point3d(seg1.EndPoint.X, seg1.EndPoint.Y, seg1.EndPoint.Z)); newline1.LayerId = LayerOfBreakLine; newline2.LayerId = LayerOfBreakLine; acBlkTbleRec.AppendEntity(newline1); acBlkTbleRec.AppendEntity(newline2); acTrans.AddNewlyCreatedDBObject(newline1, true); acTrans.AddNewlyCreatedDBObject(newline2, true); break; case "LWPOLYLINE": Polyline oldpl = new Polyline(); oldpl = (Polyline)ent1; //create the first polyline on one side of the break Polyline newpl1 = new Polyline(); newpl1.LayerId = LayerOfBreakLine; for (int x = 0; seg1.EndPoint != oldpl.GetPoint3dAt(x); x++) { newpl1.AddVertexAt(x, oldpl.GetPoint2dAt(x), 0, 0, 0); } //add end point newpl1.AddVertexAt(newpl1.NumberOfVertices, new Point2d(point2.X, point2.Y), 0, 0, 0); //create the second polyline at the other side of the break Polyline newpl2 = new Polyline(); newpl2.LayerId = LayerOfBreakLine; int i = 0; //for tracking the index of our new polyline //start at the end of the old polyline and work our way backwards to the break point for (int x = oldpl.NumberOfVertices - 1; seg1.StartPoint != oldpl.GetPoint3dAt(x); x--) { newpl2.AddVertexAt(i, oldpl.GetPoint2dAt(x), 0, 0, 0); i++; } //add end point newpl2.AddVertexAt(i, new Point2d(point1.X, point1.Y), 0, 0, 0); //erases the old polyline and adds the new two polylines to the database ent1.Erase(true); acBlkTbleRec.AppendEntity(newpl1); acBlkTbleRec.AppendEntity(newpl2); acTrans.AddNewlyCreatedDBObject(newpl1, true); acTrans.AddNewlyCreatedDBObject(newpl2, true); break; } //commit everything acTrans.Commit(); } } } } }
protected override SamplerStatus Sampler(JigPrompts prompts) { switch (jigStatus) { case 0: JigPromptPointOptions opts1 = new JigPromptPointOptions("\nSpecify the start point: ") { UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.NoZDirectionOrtho | UserInputControls.UseBasePointElevation }; PromptPointResult ppr1 = prompts.AcquirePoint(opts1); if (ppr1.Status == PromptStatus.Cancel) { return(SamplerStatus.Cancel); } if (ppr1.Value.DistanceTo(pInsert) < Tolerance.Global.EqualPoint) { return(SamplerStatus.NoChange); } else { pInsert = ppr1.Value; Vector3d disp = Point3d.Origin.GetVectorTo(pInsert); matDisplacement = Matrix3d.Displacement(disp); return(SamplerStatus.OK); } case 1: JigPromptPointOptions opts2 = new JigPromptPointOptions("\nSpecify second point:") { UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.NoZDirectionOrtho | UserInputControls.UseBasePointElevation, BasePoint = pInsert, UseBasePoint = true, Cursor = CursorType.RubberBand }; PromptPointResult ppr2 = prompts.AcquirePoint(opts2); if (ppr2.Status == PromptStatus.Cancel) { return(SamplerStatus.Cancel); } if (ppr2.Value.DistanceTo(pSecond) < Tolerance.Global.EqualPoint) { return(SamplerStatus.NoChange); } else { pSecond = ppr2.Value; Point2d start = new Point2d(pInsert.X, pInsert.Y); Point2d end = new Point2d(pSecond.X, pSecond.Y); angInsert = start.GetVectorTo(end).Angle; matRotation = Matrix3d.Rotation(angInsert, Vector3d.ZAxis, pInsert); return(SamplerStatus.OK); } default: break; } return(SamplerStatus.OK); }
public static void CreateRectangular3DArray() { // 获取当前文档和数据库,启动事务 var acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; var acCurDb = acDoc.Database; using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { // 以读模式打开块表 BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; // 以写模式打开块表记录模型空间 BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // 创建圆,圆心(2,2,0),半径0.5 var acCirc = new Circle(); acCirc.Center = new Point3d(2, 2, 0); acCirc.Radius = 0.5; // 将新对象添加到块表记录和事务 acBlkTblRec.AppendEntity(acCirc); acTrans.AddNewlyCreatedDBObject(acCirc, true); // 创建4行4列3层的矩形阵列 var nRows = 4; var nColumns = 4; var nLevels = 3; // 设置行、列、层3个方向的偏移量及阵列基角 double dRowOffset = 1; double dColumnOffset = 1; double dLevelsOffset = 4; double dArrayAng = 0; // 获取当前UCS坐标系X轴的角度 var curUCSMatrix = acDoc.Editor.CurrentUserCoordinateSystem; var curUCS = curUCSMatrix.CoordinateSystem3d; var acVec2dAng = new Vector2d(curUCS.Xaxis.X, curUCS.Xaxis.Y); // 如果UCS被旋转了,相应地调整阵列角度 dArrayAng = dArrayAng + acVec2dAng.Angle; // 使用对象界限的左上角作为阵列基点 var acExts = acCirc.Bounds.GetValueOrDefault(); var acPt2dArrayBase = new Point2d(acExts.MinPoint.X, acExts.MaxPoint.Y); // 跟踪为每列创建的对象 var acDBObjCollCols = new DBObjectCollection(); acDBObjCollCols.Add(acCirc); // 创建首列对象 var nColumnsCount = 1; while (nColumns > nColumnsCount) { var acEntClone = acCirc.Clone() as Entity; acDBObjCollCols.Add(acEntClone); // 给复制的对象计算新位置 var acPt2dTo = PolarPoints(acPt2dArrayBase, dArrayAng, dColumnOffset * nColumnsCount); var acVec2d = acPt2dArrayBase.GetVectorTo(acPt2dTo); var acVec3d = new Vector3d(acVec2d.X, acVec2d.Y, 0); acEntClone.TransformBy(Matrix3d.Displacement(acVec3d)); acBlkTblRec.AppendEntity(acEntClone); acTrans.AddNewlyCreatedDBObject(acEntClone, true); nColumnsCount = nColumnsCount + 1; } // 90度的弧度值 var dAng = 1.5708; // 跟踪每行和列中创建的对象 var acDBObjCollLvls = new DBObjectCollection(); foreach (DBObject acObj in acDBObjCollCols) { acDBObjCollLvls.Add(acObj); } // 创建每行对象 foreach (Entity acEnt in acDBObjCollCols) { var nRowsCount = 1; while (nRows > nRowsCount) { var acEntClone = acEnt.Clone() as Entity; acDBObjCollLvls.Add(acEntClone); // 给复制的对象计算新位置 var acPt2dTo = PolarPoints(acPt2dArrayBase, dArrayAng + dAng, dRowOffset * nRowsCount); var acVec2d = acPt2dArrayBase.GetVectorTo(acPt2dTo); var acVec3d = new Vector3d(acVec2d.X, acVec2d.Y, 0); acEntClone.TransformBy(Matrix3d.Displacement(acVec3d)); acBlkTblRec.AppendEntity(acEntClone); acTrans.AddNewlyCreatedDBObject(acEntClone, true); nRowsCount = nRowsCount + 1; } } // 创建3D阵列的层 foreach (Entity acEnt in acDBObjCollLvls) { var nLvlsCount = 1; while (nLevels > nLvlsCount) { var acEntClone = acEnt.Clone() as Entity; var acVec3d = new Vector3d(0, 0, dLevelsOffset * nLvlsCount); acEntClone.TransformBy(Matrix3d.Displacement(acVec3d)); acBlkTblRec.AppendEntity(acEntClone); acTrans.AddNewlyCreatedDBObject(acEntClone, true); nLvlsCount = nLvlsCount + 1; } } // 提交事务 acTrans.Commit(); } }
/// <summary> /// Gets a value indicating whether the specified point is on the segment defined by two points. /// </summary> /// <param name="pt">The instance to which the method applies.</param> /// <param name="p1">The segment start point.</param> /// <param name="p2">The segment end point.</param> /// <param name="tol">The tolerance used in comparisons.</param> /// <returns>true if the point is on the segment; otherwise, false.</returns> public static bool IsBetween(this Point2d pt, Point2d p1, Point2d p2, Tolerance tol) { return(p1.GetVectorTo(pt).GetNormal(tol).Equals(pt.GetVectorTo(p2).GetNormal(tol))); }
// override abstractne metode // prilagodena za okomita pera // izrada polyline objecta iz kojeg // će biti izrađen alignment i profile private Polyline ElementiAlignmenta() { // definiranje pointova za izradu konstrukcije if ((KodUzglavlje != null) && (KodZaglavlje != null) && (KodGlave != null)) { Point3d prviPoint = TockaNaStacionazi(KodUzglavlje); Point3d drugiPoint = TockaNaStacionazi(KodZaglavlje); Point3d _prviPoint = new Point3d(prviPoint.X, prviPoint.Y, 0); Point3d _drugiPoint = new Point3d(drugiPoint.X, drugiPoint.Y, 0); //definiranje desnog dijela konstrukcije Line pomocnaLinijaD = new Line(_prviPoint, _drugiPoint); DBObjectCollection dbLineD = pomocnaLinijaD.GetOffsetCurves(SirinaKrune / 2); Line krunadesno = (Line)dbLineD[0]; Point3d UglavljePeraD = new Point3d(krunadesno.StartPoint.X, krunadesno.StartPoint.Y, prviPoint.Z); Point3d ZaglavljePeraD = new Point3d(krunadesno.EndPoint.X, krunadesno.EndPoint.Y, drugiPoint.Z); //definiranje lijevg dijela konstrukcije Line pomocnaLinijaL = new Line(_prviPoint, _drugiPoint); DBObjectCollection dbLineL = pomocnaLinijaL.GetOffsetCurves(-SirinaKrune / 2); Line krunalijevo = (Line)dbLineL[0]; Point3d UglavljePeraL = new Point3d(krunalijevo.StartPoint.X, krunalijevo.StartPoint.Y, prviPoint.Z); Point3d ZaglavljePeraL = new Point3d(krunalijevo.EndPoint.X, krunalijevo.EndPoint.Y, drugiPoint.Z); Point3d GlavaPera = TockaNaStacionazi(KodGlave); // pretvorba 3d tocaka u 2d tocke desne strane Point2d UglavljePeraD2 = new Point2d(UglavljePeraD.X, UglavljePeraD.Y); Point2d ZaglavljePeraD2 = new Point2d(ZaglavljePeraD.X, ZaglavljePeraD.Y); // pretvorba 3d tocaka u 2d tocke lijeve strane Point2d UglavljePeraL2 = new Point2d(UglavljePeraL.X, UglavljePeraL.Y); Point2d ZaglavljePeraL2 = new Point2d(ZaglavljePeraL.X, ZaglavljePeraL.Y); // pretvorba 3d pointa glave u 2d point Point2d GlavaPera2 = new Point2d(GlavaPera.X, GlavaPera.Y); // izračun kuteva za konstrukciju polukruznice double kut1 = ZaglavljePeraL2.GetVectorTo(GlavaPera2).Angle; double kut2 = GlavaPera2.GetVectorTo(ZaglavljePeraD2).Angle; double poluKrug = Math.Tan((kut2 - kut1) / 2.0); using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTableRecord curSpace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; Polyline pLine = new Polyline(); pLine.AddVertexAt(0, UglavljePeraL2, 0, 0, 0); pLine.AddVertexAt(1, ZaglavljePeraL2, poluKrug, 0, 0); pLine.AddVertexAt(2, ZaglavljePeraD2, 0, 0, 0); pLine.AddVertexAt(3, UglavljePeraD2, 0, 0, 0); pLine.TransformBy(ed.CurrentUserCoordinateSystem); curSpace.AppendEntity(pLine); tr.AddNewlyCreatedDBObject(pLine, true); tr.Commit(); return(pLine); } } else { return(null); } }
/// <summary> /// returns the angle between X axis and the line connecting this point and pt. /// </summary> /// <param name="p0"></param> /// <param name="pt">The point which the angle will be measured to.</param> /// <returns></returns> public static double AngleTo(this Point2d p0, Point2d pt) { return(p0.GetVectorTo(pt).Angle); }
private Point2d MovePoint(Point2d p1, Point2d p2, double dist) { Vector2d p12 = p1.GetVectorTo(p2); return(p1.Add(p12.GetNormal().MultiplyBy(dist))); }
///<summary> ///Bogenkleinpunkte ///</summary> public List <Point3d> calcBogenKleinpunkte3d(Point2d ptZentrum, double dRadius, Point3d ptAnfang, Point3d ptEnde, double dStich) { List <Point3d> lsPunkte = new List <Point3d>(); Point2d ptAnfang2d = new Point2d(ptAnfang.X, ptAnfang.Y); Point2d ptEnde2d = new Point2d(ptEnde.X, ptEnde.Y); //erforderliche Sehnenlänge berechnen myAutoCAD.myUtilities objUtil = new myAutoCAD.myUtilities(); double dSehne = objUtil.calcSehne(dRadius, dStich); //Berechnung Bogenlänge double dAbstandSE = ptAnfang2d.GetDistanceTo(ptEnde2d); double dPhi = 2 * Math.Asin(dAbstandSE / (2 * dRadius)); double dBL = dRadius * dPhi; //Berechnung der Bogenlänge für Kleinpunkte double dPhi1 = 0; dPhi1 = 2 * Math.Asin(dSehne / (2 * dRadius)); double dBL1 = dRadius * dPhi1; //Vorzeichen für Phi1 festlegen (je nach Drehsinn) double dAlphaStart = objUtil.RiWi(ptZentrum, ptAnfang2d); double dAlphaEnde = objUtil.RiWi(ptZentrum, ptEnde2d); if (dAlphaStart > dAlphaEnde) { dPhi1 = -dPhi1; } //Richtungswinkel Vector2d v2dRiWi = ptZentrum.GetVectorTo(ptAnfang2d); double dRiWi = v2dRiWi.Angle; dRiWi = objUtil.RiWi(ptZentrum, ptAnfang2d); //solange Endpunkt nicht erreicht ist, Kleinpunkte berechnen double dStation = dBL1; double dWinkel = dRiWi; //dH für Höheninterpolation double dH = (ptEnde.Z - ptAnfang.Z) / dBL * dBL1; double dz = 0; while (dStation < dBL) { dWinkel += dPhi1; //dx, dy und dz berechnen double dx = dRadius * Math.Sin(dWinkel); double dy = dRadius * Math.Cos(dWinkel); dz += dH; //Kleinpunkt berechnen Point3d ptPunkt = new Point3d(ptZentrum.X + dx, ptZentrum.Y + dy, ptAnfang.Z + dz); //Punkt zu Liste hinzufügen lsPunkte.Add(ptPunkt); dStation += dBL1; } return(lsPunkte); }
public void TcJianTou() { this.point2dCollection_0 = new Point2dCollection(); this.point3d_1 = CAD.GetPoint("选择插入点: "); Point3d point3d; if (!(this.point3d_1 == point3d)) { Point2dCollection point2dCollection = this.point2dCollection_0; Point2d point2d; point2d..ctor(this.point3d_1.X, this.point3d_1.Y); point2dCollection.Add(point2d); Polyline polyline = new Polyline(); short num; for (;;) { num = checked ((short)(this.point2dCollection_0.Count - 1)); if (num >= 1) { Class36.smethod_64(polyline.ObjectId); polyline = new Polyline(); polyline.SetDatabaseDefaults(); short num2 = 0; short num3 = num; short num4 = num2; for (;;) { short num5 = num4; short num6 = num3; if (num5 > num6) { break; } polyline.AddVertexAt((int)num4, this.point2dCollection_0[(int)num4], 0.0, 0.0, 0.0); num4 += 1; } CAD.AddEnt(polyline); } short num7 = this.GangJin(); if (num7 != 1) { break; } this.point3d_1 = this.point3d_2; Point2dCollection point2dCollection2 = this.point2dCollection_0; point2d..ctor(this.point3d_2.X, this.point3d_2.Y); point2dCollection2.Add(point2d); } num = checked ((short)(this.point2dCollection_0.Count - 1)); if (num >= 1) { Class36.smethod_64(polyline.ObjectId); polyline = new Polyline(); polyline.SetDatabaseDefaults(); short num8 = 0; short num9 = num; short num10 = num8; for (;;) { short num11 = num10; short num6 = num9; if (num11 > num6) { break; } polyline.AddVertexAt((int)num10, this.point2dCollection_0[(int)num10], 0.0, 0.0, 0.0); num10 += 1; } Point2d p = this.point2dCollection_0[(int)num]; Point2d point2d2 = this.point2dCollection_0[(int)(checked (num - 1))]; double angle = p.GetVectorTo(point2d2).Angle; double num12 = p.GetDistanceTo(point2d2); num12 = Math.Min(num12, 400.0); Point2d point2dAngle = CAD.GetPoint2dAngle(p, num12, angle * 180.0 / 3.1415926535897931); polyline.AddVertexAt((int)num, this.point2dCollection_0[(int)num], 0.0, 0.0, 90.0); polyline.AddVertexAt((int)(checked (num + 1)), point2dAngle, 0.0, 90.0, 0.0); CAD.AddEnt(polyline); } } }
/// <summary> /// Gets a value indicating whether the specified point is on the segment defined by two points. /// </summary> /// <param name="pt">The instance to which the method applies.</param> /// <param name="p1">The segment start point.</param> /// <param name="p2">The segment end point.</param> /// <returns>true if the point is on the segment; otherwise, false.</returns> public static bool IsBetween(this Point2d pt, Point2d p1, Point2d p2) { return p1.GetVectorTo(pt).GetNormal().Equals(pt.GetVectorTo(p2).GetNormal()); }
public static void AddSpline() { if (!Ativacao()) { MessageBox.Show("Esta API não está ativada. Entre em contato com a SELTTE!"); return; } pt1x = GetPoint(); // Caso não se clique em lugar algum, o comando é finalizado if (pt1x.X == 0.0 && pt1x.Y == 0.0) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; editor.WriteMessage("\n-> Cancelado!\n"); return; } pt2x = GetPoint(); // Caso não se clique em lugar algum, o comando é finalizado if (pt2x.X == 0.0 && pt2x.Y == 0.0) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; editor.WriteMessage("\n-> Cancelado!\n"); return; } pt1 = new Point2d(pt1x.X, pt1x.Y); pt2 = new Point2d(pt2x.X, pt2x.Y); if (pt1.X > pt2.X || pt1.Y > pt2.Y) { Point2d ptx = pt1; pt1 = pt2; pt2 = ptx; } // Get the current document and database Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor ed = acDoc.Editor; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Block table for read BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; // Open the Block table record Model space for write BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; double anglePt1Pt2 = pt1.GetVectorTo(pt2).Angle; if (anglePt1Pt2 > Math.PI) { anglePt1Pt2 -= Math.PI; } //PolarPoints(pt1.Add((pt2.Subtract(pt1.GetAsVector()) / 4).GetAsVector()), pt1.GetVectorTo(pt2).GetAngleTo(pt2.GetAsVector()) + Math.PI / 2, 10); Point2d pt3 = PolarPoints(pt1.Add(pt1.GetVectorTo(pt2) / 4), anglePt1Pt2 + Math.PI / 2, pt1.GetDistanceTo(pt2) * 0.1); Point2d pt4 = PolarPoints(pt2.Subtract((pt2.Subtract(pt1.GetAsVector()) / 4).GetAsVector()), anglePt1Pt2 - Math.PI / 2, pt1.GetDistanceTo(pt2) * 0.1); Point3d pt5 = new Point3d(pt1.X, pt1.Y, 0); // pt1 em 3d Point3d pt6 = new Point3d(pt3.X, pt3.Y, 0); // pt3 em 3d Point3d pt7 = new Point3d(pt4.X, pt4.Y, 0); // pt4 em 3d Point3d pt8 = new Point3d(pt2.X, pt2.Y, 0); // pt2 em 3d // Define the fit points for the spline Point3dCollection ptColl = new Point3dCollection { pt5, pt6, pt7, pt8 }; // Create a spline through (0, 0, 0), (5, 5, 0), and (10, 0, 0) with a // start and end tangency of (0.5, 0.5, 0.0) using (Spline acSpline = new Spline(ptColl, new Point3d(0.0000, 0.0000, 0.0000).GetAsVector(), new Point3d(0.0000, 0.0000, 0.0000).GetAsVector(), 0, 0.0)) { // Add the new object to the block table record and the transaction acBlkTblRec.AppendEntity(acSpline); acTrans.AddNewlyCreatedDBObject(acSpline, true); } acDoc.SendStringToExecute("Trim ", true, false, false); // Save the new line to the database acTrans.Commit(); } }