// public Movil(ref ObjectId line, ref ObjectId mobile, double minSeparation, double maxSeparation, bool loopTravel) { this.line = line; this.mobile = mobile; this.dPromMin = minSeparation; this.dPromMax = maxSeparation; this.loopTravel = loopTravel; this.goal = false; this.ruta = Lab3.DBMan.OpenEnity(line) as Polyline; this.bloque = Lab3.DBMan.OpenEnity(mobile) as BlockReference; this.bloqueCentro = new Point3d((bloque.GeometricExtents.MinPoint.X + bloque.GeometricExtents.MaxPoint.X) / 2, (bloque.GeometricExtents.MinPoint.Y + bloque.GeometricExtents.MaxPoint.Y) / 2, 0); this.numeroSegmentos = this.ruta.NumberOfVertices - 1; this.segmentoActualIndex = 0; this.segmentoActual = this.ruta.GetLineSegment2dAt(segmentoActualIndex); Lab3.DBMan.UpdateBlockPosition(new Point3d(this.segmentoActual.StartPoint.X, this.segmentoActual.StartPoint.Y, 0), mobile); // AttributeManager attribute = new AttributeManager(mobile); attribute.SetAttribute("Velocity", this.velocity+" [Kms/hr]"); // this.pointActualCurve = 0; this.velocityScale = 0.00001f; this.velocity = this.UpdateDireccion(); Lab3.DBMan.UpdateBlockRotation(new Vector2d(this.velocity.X, this.velocity.Y).Angle, this.mobile); }
private Curve2d StructurePosCurve(CivilDB.Structure str) { switch (str.BoundingShape) { case CivilDB.BoundingShapeType.Cylinder: return(new CircularArc2d(new Point2d(str.Location.X, str.Location.Y), str.InnerDiameterOrWidth / 2)); case CivilDB.BoundingShapeType.Box: //создать прямоугольник с учетом поворота и точки вставки Vector2d loc = new Vector2d(str.Location.X, str.Location.Y); Matrix2d rotation = Matrix2d.Rotation(str.Rotation, Point2d.Origin); Point2d p0 = (new Point2d(-str.InnerDiameterOrWidth / 2, -str.InnerLength / 2)).TransformBy(rotation) + loc; Point2d p1 = (new Point2d(-str.InnerDiameterOrWidth / 2, str.InnerLength / 2)).TransformBy(rotation) + loc; Point2d p2 = (new Point2d(str.InnerDiameterOrWidth / 2, str.InnerLength / 2)).TransformBy(rotation) + loc; Point2d p3 = (new Point2d(str.InnerDiameterOrWidth / 2, -str.InnerLength / 2)).TransformBy(rotation) + loc; LineSegment2d side0 = new LineSegment2d(p0, p1); LineSegment2d side1 = new LineSegment2d(p1, p2); LineSegment2d side2 = new LineSegment2d(p2, p3); LineSegment2d side3 = new LineSegment2d(p3, p0); return(new CompositeCurve2d(new Curve2d[] { side0, side1, side2, side3 })); default: return(null); } }
private static LineSegment2d GetExtendLineSegmentFromPolyline2d(Polyline2d polyline2d, Point3d point, Transaction transaction) { LineSegment2d result = null; var vertices = new List <Vertex2d>(); foreach (ObjectId objId in polyline2d) { var vertex = transaction.GetObject(objId, OpenMode.ForRead) as Vertex2d; vertices.Add(vertex); } var point2D = new Point2d(point.X, point.Y); if (polyline2d.EndPoint == point) { var startPoint = vertices[vertices.Count - 2].Position; var startPoint2D = new Point2d(startPoint.X, startPoint.Y); result = new LineSegment2d(startPoint2D, point2D); } else { var endPoint = vertices[1].Position; var endPoint2D = new Point2d(endPoint.X, endPoint.Y); result = new LineSegment2d(point2D, endPoint2D); } 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); }
// Adds an arc (fillet) at the specified vertex. Returns 1 if the operation succeeded, 0 if it failed. public static int FilletAt(this Polyline pline, int index, double radius) { int prev = index == 0 && pline.Closed ? pline.NumberOfVertices - 1 : index - 1; if (pline.GetSegmentType(prev) != SegmentType.Line || pline.GetSegmentType(index) != SegmentType.Line) { return(0); } LineSegment2d seg1 = pline.GetLineSegment2dAt(prev); LineSegment2d seg2 = pline.GetLineSegment2dAt(index); Vector2d vec1 = seg1.StartPoint - seg1.EndPoint; Vector2d vec2 = seg2.EndPoint - seg2.StartPoint; double angle = (Math.PI - vec1.GetAngleTo(vec2)) / 2.0; double dist = radius * Math.Tan(angle); if (dist > seg1.Length || dist > seg2.Length) { return(0); } Point2d pt1 = seg1.EndPoint + vec1.GetNormal() * dist; Point2d pt2 = seg2.StartPoint + vec2.GetNormal() * dist; double bulge = Math.Tan(angle / 2.0); if (Clockwise(seg1.StartPoint, seg1.EndPoint, seg2.EndPoint)) { bulge = -bulge; } pline.AddVertexAt(index, pt1, bulge, 0.0, 0.0); pline.SetPointAt(index + 1, pt2); return(1); }
private bool AreDivided(TextInfo upper, TextInfo lower, List /*SortedSet*/ <LineSegment2d> horizontalLines) { bool divided = false; //SortedSet<LineSegment2d> horizontalsBetween // = horizontalLines.GetViewBetween(new LineSegment2d(lower.CenterPt, Vector2d.XAxis), // new LineSegment2d(upper.CenterPt, Vector2d.XAxis)); //if (horizontalsBetween.Count > 0) //{ LineSegment2d divider = //horizontalsBetween.ToList() horizontalLines .Find(h => h.StartPoint.X <= upper.CenterPt.X && h.EndPoint.X >= upper.CenterPt.X && h.StartPoint.Y <= upper.CenterPt.Y && h.StartPoint.Y >= lower.CenterPt.Y ); if (divider != null) { divided = true; } //} return(divided); }
//#foreach instanced to 'Double2' /// <summary> /// Gets line. /// </summary> /// <param name="index">The line index.</param> /// <remarks>This is not performance wise getter.</remarks> /// <returns></returns> public LineSegment2d Get2d(uint index) { LineSegment2d t = new LineSegment2d(); Get(CommonComponents.Position, index, t); return(t); }
public static LineSegment2d[] GetTangentsTo([NotNull] this CircularArc2d arc, Point2d pt) { // check if the point is inside the circle var center = arc.Center; if (pt.GetDistanceTo(center) <= arc.Radius) { return(null); } var vec = center.GetVectorTo(pt) / 2.0; var tmp = new CircularArc2d(center + vec, vec.Length); var inters = arc.IntersectWith(tmp); if (inters == null) { return(null); } var result = new LineSegment2d[2]; var v1 = inters[0] - center; var i = vec.X * v1.Y - vec.Y - v1.X > 0 ? 0 : 1; var j = i ^ 1; result[i] = new LineSegment2d(inters[0], pt); result[j] = new LineSegment2d(inters[1], pt); return(result); }
private List <Vector3> FindIntersections(List <LineSegment> segs) { List <Vector3> intersectionList = new List <Vector3>(); //Mapeia os pontos pro 2d descartando o y LineSegment2d.ResetCounter(); var _2dSegments = segs.Select <LineSegment, LineSegment2d>(s => new LineSegment2d(s.Point1, s.Point2)).ToList(); var _2dSegsQueue = new Queue <LineSegment2d>(_2dSegments); while (_2dSegsQueue.Count > 0) { var s1 = _2dSegsQueue.Dequeue(); foreach (var s2 in _2dSegsQueue) { Vector2 intersectionIn2d; bool doesIntersect = Line2dIntersectionService.LineSegmentsIntersection(s1.Point1, s1.Point2, s2.Point1, s2.Point2, out intersectionIn2d); if (doesIntersect) { //A posição paramétrica no segmento 1 do ponto de interseção. Poderia ser no segmento 2 mas tanto faz, a posição espacial vai ser a mesma. float gammaP2d = (intersectionIn2d - s1.Point1).magnitude / (s1.Point2 - s1.Point1).magnitude; //Relação entre as magnitudes do vetor2d e do vetor3d que corresponde a ele var R = (s1.Point2 - s1.Point1).magnitude / s1.OriginalMagnitude;//(segments[i].Point2 - segments[i].Point1).magnitude; //o parâmetro no vetor 3d var gammaP3d = gammaP2d * R; //o ponto da interseção no 3d var p3d = s1.OriginalSegment.Point1 + gammaP3d * (s1.OriginalSegment.Point2 - s1.OriginalSegment.Point1); intersectionList.Add(p3d); } } } return(intersectionList); }
/// <summary> /// An array getter, optimized by reusing mappings. /// </summary> /// <param name="lineIndex">The line index offset.</param> /// <param name="positionComponent">The position component.</param> /// <param name="storage">Where to store result.</param> public void Get(string positionComponent, uint lineIndex, LineSegment2d[] storage) { if (lineIndex + storage.Length >= shapeCount) { throw new ArgumentException("Index out of range, not that many triangles."); } if (indexBuffer != null) { uint[] indices = indexBuffer.Getui(lineIndex * 2, (uint)storage.Length * 2); Vector2d[] data = query.Get2d(positionComponent, indices); for (int i = 0; i < storage.Length; i++) { storage[i] = new LineSegment2d(data[i * 2], data[i * 2 + 1]); } } else { Vector2d[] data = query.Get2d(positionComponent, lineIndex * 2, (uint)storage.Length * 2); for (int i = 0; i < storage.Length; i++) { storage[i] = new LineSegment2d(data[i * 2], data[i * 2 + 1]); } } }
private int Fillet(Polyline pline, double radius, int index1, int index2) { if (pline.GetSegmentType(index1) != SegmentType.Line || pline.GetSegmentType(index2) != SegmentType.Line) { return(0); } LineSegment2d seg1 = pline.GetLineSegment2dAt(index1); LineSegment2d seg2 = pline.GetLineSegment2dAt(index2); Vector2d vec1 = seg1.StartPoint - seg1.EndPoint; Vector2d vec2 = seg2.EndPoint - seg2.StartPoint; double angle = vec1.GetAngleTo(vec2) / 2.0; double dist = radius / Math.Tan(angle); if (dist > seg1.Length || dist > seg2.Length) { return(0); } Point2d pt1 = seg1.EndPoint.TransformBy(Matrix2d.Displacement(vec1.GetNormal() * dist)); Point2d pt2 = seg2.StartPoint.TransformBy(Matrix2d.Displacement(vec2.GetNormal() * dist)); double bulge = Math.Tan((Math.PI / 2.0 - angle) / 2.0); if (Clockwise(seg1.StartPoint, seg1.EndPoint, seg2.EndPoint)) { bulge = -bulge; } pline.AddVertexAt(index2, pt1, bulge, 0.0, 0.0); pline.SetPointAt(index2 + 1, pt2); return(1); }
/// <summary> /// Gets line. /// </summary> /// <param name="index">The line index.</param> /// <param name="positionComponent">The component where we look for position, must be /// correct format.</param> /// <remarks>This is not performance wise getter.</remarks> public LineSegment2d Get2d(string positionComponent, uint index) { LineSegment2d t = new LineSegment2d(); Get(positionComponent, index, t); return(t); }
/// <summary> 检查边坡是否与指定的标高相交,并返回交点在 AutoCAD 中的几何坐标 </summary> /// <param name="slp"></param> /// <param name="ele"></param> /// <param name="intersPt">返回交点</param> /// <returns></returns> private static bool ValidateElevation(SlopeLine slp, CutMethod method, double ele, out Point2d intersPt, out Slope slopeSeg) { intersPt = Point2d.Origin; slopeSeg = null; var slpData = slp.XData; var sec = slp.Section; var cutY = GetCutY(slpData, sec, method, ele); // sec.GetYFromElev(ele); // 指定的标高在此断面中所对应的 AutoCAD 中的坐标Y值 const double tolerance = 0.01; foreach (var seg in slpData.Slopes) { bool within = (seg.TopPoint.Y - cutY >= tolerance) && (cutY - seg.BottomPoint.Y >= tolerance); if (within) // 说明此子边坡与指定的标高相交 { var l = new LineSegment2d(new Point2d(seg.BottomPoint.X, seg.BottomPoint.Y), new Point2d(seg.TopPoint.X, seg.TopPoint.Y)); var intersPts = l.IntersectWith(new Line2d(new Point2d(0, cutY), new Vector2d(1, 0))); if (intersPts != null) { slopeSeg = seg; intersPt = intersPts[0]; return(true); } } } return(false); }
/// <summary> /// Creates a new instance of PolylineSegment from a LineSegment2d /// </summary> /// <param name="line">A LineSegment2d instance.</param> public PolylineSegment(LineSegment2d line) { _startPoint = line.StartPoint; _endPoint = line.EndPoint; _bulge = 0.0; _startWidth = 0.0; _endWidth = 0.0; }
/// <summary> /// Creates a new instance of PolylineSegment from a LineSegment2d /// </summary> /// <param name="line">A LineSegment2d instance.</param> public PolylineSegment([NotNull] LineSegment2d line) { _startPoint = line.StartPoint; _endPoint = line.EndPoint; Bulge = 0.0; StartWidth = 0.0; EndWidth = 0.0; }
bool IsSegmentsReallyNear(LineSegment2d source, LineSegment2d target) { // Duplicate should return. if (source.StartPoint == target.StartPoint && source.EndPoint == target.EndPoint || source.EndPoint == target.StartPoint && source.StartPoint == target.EndPoint) { return(false); } if (IsColinear(source, target)) { return(false); } // source segment and target segment's angle should less than 20 var sourceVector = source.Direction; var targetVector = target.Direction; var angle = sourceVector.GetAngleTo(targetVector); if (angle.Larger(Math.PI / 36.0) && angle.Smaller(Math.PI * 35.0 / 36.0)) { return(false); } // Check two segments' distance var sourceLine2d = new Line2d(source.StartPoint, source.EndPoint); var targetLine2d = new Line2d(target.StartPoint, target.EndPoint); var dist1 = sourceLine2d.GetDistanceTo(target.StartPoint); var dist2 = sourceLine2d.GetDistanceTo(target.EndPoint); // If they are both equal to 0.0, means duplicate, just return. if (dist1.EqualsWithTolerance(0.0, Tolerance.Global.EqualPoint) && dist2.EqualsWithTolerance(0.0, Tolerance.Global.EqualPoint)) { return(false); } var dist3 = targetLine2d.GetDistanceTo(source.StartPoint); var dist4 = targetLine2d.GetDistanceTo(source.EndPoint); if ((dist1.Larger(_tolerance) || dist2.Larger(_tolerance)) && (dist3.Larger(_tolerance) || dist4.Larger(_tolerance))) { return(false); } // Filter out the situation if a short segment (length < _tolerance) is connect to another. var pt1OnSource = source.GetClosestPointTo(target.StartPoint); var pt2OnSource = source.GetClosestPointTo(target.EndPoint); if (pt1OnSource.Point == pt2OnSource.Point) { return(false); } return(true); }
private Vector2d GetWindowPerpVector(LineSegment2d segOwner, Polyline contour) { var vecSegPerp = segOwner.Direction.GetPerpendicularVector().GetNormal(); var pt = ptCalc2d + vecSegPerp; if (contour.IsPointInsidePolygon(pt.Convert3d())) { vecSegPerp = vecSegPerp.Negate(); } return(vecSegPerp); }
private static List <Point2d> CalcGeologPtsByDepth(Point2d p0, Point2d p1, int[] interval, List <Point2d> groundSurfPoly, double depthMultipier) { List <Point2d> polygonPts = new List <Point2d>(); LineSegment2d geologSegment = new LineSegment2d(p0, p1); //начало отрезка LineSegment2d surfSegment0 = new LineSegment2d(groundSurfPoly[interval[0]], groundSurfPoly[interval[0] + 1]); Line2d vert0 = new Line2d(p0, Vector2d.YAxis); CurveCurveIntersector2d intersector0 = new CurveCurveIntersector2d(vert0, surfSegment0); if (intersector0.NumberOfIntersectionPoints > 0) { Point2d surfPt0 = intersector0.GetPointOnCurve2(0).Point; double depth0 = (surfPt0.Y - p0.Y) * depthMultipier; Point2d convertedGeologPt0 = surfPt0 - Vector2d.YAxis * depth0; polygonPts.Add(convertedGeologPt0); } //все точки поверхности между началом и концом отрезка if (!geologSegment.Direction.IsParallelTo(Vector2d.YAxis)) { for (int i = interval[0]; i <= interval[1]; i++) { Point2d surfPt = groundSurfPoly[i]; Line2d vert = new Line2d(surfPt, Vector2d.YAxis); CurveCurveIntersector2d intersector = new CurveCurveIntersector2d(vert, geologSegment); if (intersector.NumberOfIntersectionPoints > 0) { Point2d geologPt = intersector.GetPointOnCurve2(0).Point; double depth = (surfPt.Y - geologPt.Y) * depthMultipier; Point2d convertedGeologPt = surfPt - Vector2d.YAxis * depth; polygonPts.Add(convertedGeologPt); } } } //конец отрезка LineSegment2d surfSegment1 = new LineSegment2d(groundSurfPoly[interval[1] - 1], groundSurfPoly[interval[1]]); Line2d vert1 = new Line2d(p1, Vector2d.YAxis); CurveCurveIntersector2d intersector1 = new CurveCurveIntersector2d(vert1, surfSegment1); if (intersector1.NumberOfIntersectionPoints > 0) { Point2d surfPt1 = intersector1.GetPointOnCurve2(0).Point; double depth1 = (surfPt1.Y - p1.Y) * depthMultipier; Point2d convertedGeologPt1 = surfPt1 - Vector2d.YAxis * depth1; polygonPts.Add(convertedGeologPt1); } return(polygonPts); }
// 多段线和直线求交点 private void PolyIntersectWithLine(Polyline poly, Line line, double tol, ref Point3dCollection points) { Point2dCollection intPoints2d = new Point2dCollection(); // 获得直线对应的几何类 LineSegment2d geLine = new LineSegment2d(ToPoint2d(line.StartPoint), ToPoint2d(line.EndPoint)); // 每一段分别计算交点 Tolerance tolerance = new Tolerance(tol, tol); for (int i = 0; i < poly.NumberOfVertices; i++) { if (i < poly.NumberOfVertices - 1 || poly.Closed) { SegmentType st = poly.GetSegmentType(i); if (st == SegmentType.Line) { LineSegment2d geLineSeg = poly.GetLineSegment2dAt(i); Point2d[] pts = geLineSeg.IntersectWith(geLine, tolerance); if (pts != null) { for (int j = 0; j < pts.Length; j++) { if (FindPointIn(intPoints2d, pts[j], tol) < 0) { intPoints2d.Add(pts[j]); } } } } else if (st == SegmentType.Arc) { CircularArc2d geArcSeg = poly.GetArcSegment2dAt(i); Point2d[] pts = geArcSeg.IntersectWith(geLine, tolerance); if (pts != null) { for (int j = 0; j < pts.Length; j++) { if (FindPointIn(intPoints2d, pts[j], tol) < 0) { intPoints2d.Add(pts[j]); } } } } } } for (int i = 0; i < intPoints2d.Count; i++) { points.Add(ToPoint3d(intPoints2d[i])); } }
/// <summary> /// select a SketchLine and SketchCircle and get intersect points of LineSegment and circle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button1_Click(object sender, EventArgs e) { if (((mApp.ActiveDocument != null))) { if ((mApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject)) { PartDocument oDoc = mApp.ActiveDocument as PartDocument; if ((oDoc.SelectSet.Count == 2)) { if (((oDoc.SelectSet[1]) is SketchLine & (oDoc.SelectSet[2]) is SketchCircle)) { SketchLine oSketchLine = oDoc.SelectSet[1] as SketchLine; SketchCircle oSketchCircle = oDoc.SelectSet[2] as SketchCircle; LineSegment2d oLineSeg2d = oSketchLine.Geometry; Circle2d oCircle2d = oSketchCircle.Geometry; ObjectsEnumerator objectsEnum = oLineSeg2d.IntersectWithCurve(oCircle2d, 0.0001); if ((objectsEnum == null)) { System.Windows.Forms.MessageBox.Show("No physical intersection between Line and Circle"); return; } string strResult = "Intersection point(s): \n"; int i = 0; for (i = 1; i <= objectsEnum.Count; i++) { Point2d oPoint = objectsEnum[i] as Point2d; strResult += "[" + oPoint.X.ToString("F2") + ", " + oPoint.Y.ToString("F2") + "] \n"; } System.Windows.Forms.MessageBox.Show(strResult, "BRep Sample"); return; } else { System.Windows.Forms.MessageBox.Show("Entity 1 must be a SketchLine, Entity 2 must be a SketchCircle", "BRep Sample"); return; } } else { System.Windows.Forms.MessageBox.Show("Incorrect selection of sketch entities", "BRep Sample"); return; } } } }
private bool OverlapBorder(Point2d segPt1, Point2d segPt2, List <Line2d> borderGuidings) { LineSegment2d line = new LineSegment2d(segPt1, segPt2); foreach (Line2d border in borderGuidings) { if (border.Overlap(line) != null) { return(true); } } return(false); }
/// <summary> /// Расчет пересечений двух линий /// С учетом допусков автокада /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="p3"></param> /// <param name="p4"></param> /// <returns></returns> public static Point2d?GetLinesIntersectionAcad(Point2d p1, Point2d p2, Point2d p3, Point2d p4) { Point2d? pt = null; LineSegment2d line1 = new LineSegment2d(p1, p2); LineSegment2d line2 = new LineSegment2d(p3, p4); CurveCurveIntersector2d intersector = new CurveCurveIntersector2d(line1, line2); if (intersector.NumberOfIntersectionPoints > 0) { pt = intersector.GetIntersectionPoint(0); } return(pt); }
public LineSegment2d GetLineSegment2dAt(int index) { if (base.isInstanced()) { LineSegment2d GetLineSegment2dAt = BasePolyline.GetLineSegment2dAt(index); tr.Dispose(); return(GetLineSegment2dAt); } else { return(BasePolyline.GetLineSegment2dAt(index)); } }
private List <LineSegment> SplitSegmentsV2(List <LineSegment> segs) { LineSegment2d.ResetCounter(); var _2dSegments = segs.Select <LineSegment, LineSegment2d>(s => new LineSegment2d(s.Point1, s.Point2)).ToList(); var SplitedSegments = new List <LineSegment>(); for (int i = 0; i < _2dSegments.Count; i++) { bool isIsolated = true; var s1 = _2dSegments[i]; for (int j = 0; j < _2dSegments.Count; j++) { var s2 = _2dSegments[j]; if (s1 == s2) { continue; } Vector2 intersectionIn2d; bool doesIntersect = Line2dIntersectionService.LineSegmentsIntersection(s1.Point1, s1.Point2, s2.Point1, s2.Point2, out intersectionIn2d); if (doesIntersect) { //Passagem do ponto de interseção do 2d pro 3d. //A posição paramétrica no segmento 1 do ponto de interseção. Poderia ser no segmento 2 mas tanto faz, a posição espacial vai ser a mesma. float gammaP2d = (intersectionIn2d - s1.Point1).magnitude / (s1.Point2 - s1.Point1).magnitude; //Relação entre as magnitudes do vetor2d e do vetor3d que corresponde a ele var R = (s1.Point2 - s1.Point1).magnitude / s1.OriginalMagnitude;//(segments[i].Point2 - segments[i].Point1).magnitude; //o parâmetro no vetor 3d var gammaP3d = gammaP2d * R; //o ponto da interseção no 3d var intersectionPoint = s1.OriginalSegment.Point1 + gammaP3d * (s1.OriginalSegment.Point2 - s1.OriginalSegment.Point1); //Os dois segmentos interceptantes devem ser divididos. Isso vai fazer com que 2 virem 4. O ponto de divisão é o ponto de interseção no 3d. //1)Segmento 1 LineSegment s1A = new LineSegment(segs[i].Point1, intersectionPoint); LineSegment s1B = new LineSegment(intersectionPoint, segs[i].Point2); //LineSegment s2A = new LineSegment(s2.Point1, intersectionPoint); //Pq vou passar 2 vezes aqui. //LineSegment s2B = new LineSegment(intersectionPoint, s2.Point2); SplitedSegments.Add(s1A); SplitedSegments.Add(s1B); //SplitedSegments.Add(s2A); //SplitedSegments.Add(s2B); isIsolated = false; } } if (isIsolated) { SplitedSegments.Add(s1.OriginalSegment); } } Debug.Log($"Qtd = {SplitedSegments.Count}"); return(SplitedSegments); }
private void CreatePositionCurve(List <Point2d> polyPts) { List <Curve2d> segments = new List <Curve2d>(); for (int i = 0; i < polyPts.Count - 1; i++) { Point2d p0 = polyPts[i]; Point2d p1 = polyPts[i + 1]; LineSegment2d segment = new LineSegment2d(p0, p1); segments.Add(segment); } PositionCurve = new CompositeCurve2d(segments.ToArray()); }
//#endfor instanced to 'Vector2f' #endregion #region Private Members //#foreach instanced to 'Vector2d' /// <summary> /// Returns true, if p0 is upper point, p1, p2 are lower, false otherwise. /// </summary> static bool CalcPathIntersection(Vector2d a, Vector2d b, Vector2d c, double width, out Vector2d p0, out Vector2d p1, out Vector2d p2) { // We first generate two vectors. Vector2d dir1 = b - a; Vector2d dir2 = c - b; // We generate two perpendicular vectors. Vector2d grad1 = new Vector2d(-dir1.Y, dir1.X).Normal; Vector2d grad2 = new Vector2d(-dir2.Y, dir2.X).Normal; // We now generate 4 line segments. LineSegment2d seg1Up = new LineSegment2d(a + grad1 * width, b + grad1 * width); LineSegment2d seg1Down = new LineSegment2d(a - grad1 * width, b - grad1 * width); LineSegment2d seg2Up = new LineSegment2d(b + grad2 * width, c + grad2 * width); LineSegment2d seg2Down = new LineSegment2d(b - grad2 * width, c - grad2 * width); // We calculate intersections. double t1, t2; if (Intersection.Intersect(seg1Up, seg2Up, out t1, out t2)) { // If they intersect, we have point 0. p0 = seg1Up.Sample(t1); p1 = seg1Down.B; p2 = seg2Down.A; return(true); } else if (Intersection.Intersect(seg1Down, seg2Down, out t1, out t2)) { p0 = seg1Down.Sample(t1); p1 = seg1Up.B; p2 = seg2Up.A; return(false); } else { // If result is this, we have no intersections, numeric error. We use variables of one. p0 = seg1Up.B; p1 = p2 = seg1Down.B; return(true); } }
/// <summary> 将三维折线多段线投影到XY平面上,以转换为二维多段线 </summary> /// <param name="pl"></param> /// <returns></returns> public static CompositeCurve2d Get2dLinearCurve(this CompositeCurve3d pl) { LineSegment2d seg2d; var curve3ds = pl.GetCurves(); var seg2ds = new Curve2d[curve3ds.Length]; Curve3d c; for (int i = 0; i < curve3ds.Length; i++) { c = curve3ds[i]; seg2d = new LineSegment2d(c.StartPoint.ToXYPlane(), c.EndPoint.ToXYPlane()); seg2ds[i] = (seg2d); } return(new CompositeCurve2d(seg2ds)); }
private void GetEdgeInformation(Polyline pline, ref Curve2dCollection plCurves, ref IntegerCollection edgeTypes) { int segCount = pline.NumberOfVertices; for (int cnt = 0; cnt < segCount; cnt++) { SegmentType type = pline.GetSegmentType(cnt); switch (type) { case SegmentType.Arc: CircularArc2d arc2d = pline.GetArcSegment2dAt(cnt); plCurves.Add(arc2d); edgeTypes.Add((int)Enum.Parse(typeof(HatchEdgeType), HatchEdgeType.CircularArc.ToString())); break; case SegmentType.Line: LineSegment2d line2d = pline.GetLineSegment2dAt(cnt); plCurves.Add(line2d); edgeTypes.Add((int)Enum.Parse(typeof(HatchEdgeType), HatchEdgeType.Line.ToString())); break; case SegmentType.Coincident: break; case SegmentType.Empty: break; case SegmentType.Point: break; } } }
public bool Intersection(LineSegment2d ls, ref Vector2 intersection) { float isectX = 0.0f; float isectY = 0.0f; bool result = Get_line_intersection(pointA.x, pointA.y, pointB.x, pointB.y, ls.pointA.x, ls.pointA.y, ls.pointB.x, ls.pointB.y, ref isectX, ref isectY); if (result) { intersection = new Vector2(isectX, isectY); } return(result); }
/// <summary> /// Returns the parameter value of point. /// </summary> /// <param name="pt">The Point 2d whose get the PolylineSegment parameter at.</param> /// <returns>A double between 0.0 and 1.0, or -1.0 if the point does not lie on the segment.</returns> public double GetParameterOf(Point2d pt) { if (IsLinear) { LineSegment2d line = ToLineSegment(); return(line.IsOn(pt) ? _startPoint.GetDistanceTo(pt) / line.Length : -1.0); } else { CircularArc2d arc = ToCircularArc(); return(arc.IsOn(pt) ? arc.GetLength(arc.GetParameterOf(_startPoint), arc.GetParameterOf(pt)) / arc.GetLength(arc.GetParameterOf(_startPoint), arc.GetParameterOf(_endPoint)) : -1.0); } }
public override void Input(List <Entity> objects) { foreach (Entity ent in objects) { if (ent is Line) { segments.Add(new StraitItemSegment(((Line)ent).Length)); } else if (ent is Arc) { segments.Add(new RadiusItemSegment(ent as Arc)); } else if (ent is Polyline) { Polyline pl = ent as Polyline; int count; if (pl.Closed) { count = pl.NumberOfVertices; } else { count = pl.NumberOfVertices - 1; } for (int j = 0; j < count; j++) { SegmentType st = pl.GetSegmentType(j); if (st == SegmentType.Line) { LineSegment2d lsd = pl.GetLineSegment2dAt(j); segments.Add(new StraitItemSegment(lsd.Length)); } else if (st == SegmentType.Arc) { CircularArc2d arc_s = pl.GetArcSegment2dAt(j); Plane pn = new Plane(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis); Arc arc = new Arc(new Point3d(pn, arc_s.Center), Vector3d.ZAxis, arc_s.Radius, arc_s.StartAngle, arc_s.EndAngle); segments.Add(new RadiusItemSegment(arc)); } } } } base.count = ItemInput.ItemCount(); status = true; }
/// <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> /// Returns the tangents between the active CircularArc2d 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 other one. /// </remarks> /// <param name="arc">The instance to which this method applies.</param> /// <param name="other">The CircularArc2d to which searched for tangents.</param> /// <param name="flags">An enum value specifying which type of tangent is returned.</param> /// <returns>An array of LineSegment2d representing the tangents (maybe 2 or 4) or null if there is none.</returns> public static LineSegment2d[] GetTangentsTo(this CircularArc2d arc, CircularArc2d other, TangentType flags) { // check if a circle is inside the other double dist = arc.Center.GetDistanceTo(other.Center); if (dist - Math.Abs(arc.Radius - other.Radius) <= Tolerance.Global.EqualPoint) return null; // check if circles overlap bool overlap = arc.Radius + other.Radius >= dist; if (overlap && flags == TangentType.Inner) return null; CircularArc2d tmp1, tmp2; Point2d[] inters; Vector2d vec1, vec2, vec = other.Center - arc.Center; int i, j; LineSegment2d[] result = new LineSegment2d[(int)flags == 3 && !overlap ? 4 : 2]; // outer tangents if ((flags & TangentType.Outer) > 0) { if (arc.Radius == other.Radius) { Line2d perp = new Line2d(arc.Center, vec.GetPerpendicularVector()); inters = arc.IntersectWith(perp); if (inters == null) return null; vec1 = (inters[0] - arc.Center).GetNormal(); vec2 = (inters[1] - arc.Center).GetNormal(); i = vec.X * vec1.Y - vec.Y - vec1.X > 0 ? 0 : 1; j = i ^ 1; result[i] = new LineSegment2d(inters[0], inters[0] + vec); result[j] = new LineSegment2d(inters[1], inters[1] + vec); } else { Point2d center = arc.Radius < other.Radius ? other.Center : arc.Center; tmp1 = new CircularArc2d(center, Math.Abs(arc.Radius - other.Radius)); tmp2 = new CircularArc2d(arc.Center + vec / 2.0, dist / 2.0); inters = tmp1.IntersectWith(tmp2); if (inters == null) return null; vec1 = (inters[0] - center).GetNormal(); vec2 = (inters[1] - center).GetNormal(); i = vec.X * vec1.Y - vec.Y - vec1.X > 0 ? 0 : 1; j = i ^ 1; result[i] = new LineSegment2d(arc.Center + vec1 * arc.Radius, other.Center + vec1 * other.Radius); result[j] = new LineSegment2d(arc.Center + vec2 * arc.Radius, other.Center + vec2 * other.Radius); } } // inner tangents if ((flags & TangentType.Inner) > 0 && !overlap) { double ratio = (arc.Radius / (arc.Radius + other.Radius)) / 2.0; tmp1 = new CircularArc2d(arc.Center + vec * ratio, dist * ratio); inters = arc.IntersectWith(tmp1); if (inters == null) return null; vec1 = (inters[0] - arc.Center).GetNormal(); vec2 = (inters[1] - arc.Center).GetNormal(); i = vec.X * vec1.Y - vec.Y - vec1.X > 0 ? 2 : 3; j = i == 2 ? 3 : 2; result[i] = new LineSegment2d(arc.Center + vec1 * arc.Radius, other.Center + vec1.Negate() * other.Radius); result[j] = new LineSegment2d(arc.Center + vec2 * arc.Radius, other.Center + vec2.Negate() * other.Radius); } return result; }
// public void Move() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; // if (this.goal) return; ApplyTransforms(); // if (line.IsValid && mobile.IsValid) { if (bloque.Position.DistanceTo(new Point3d(segmentoActual.EndPoint.X, segmentoActual.EndPoint.Y, 0)) < 10) { segmentoActualIndex++; if (segmentoActualIndex + 1 > numeroSegmentos) { if (loopTravel) { pointActualCurve = 0; segmentoActualIndex = 0; this.goal = false; //ed.WriteMessage("REINICIO!. {0} de {1}\n", segmentoActualIndex + 1, numeroSegmentos); segmentoActual = this.ruta.GetLineSegment2dAt(segmentoActualIndex); Lab3.DBMan.UpdateBlockPosition(new Point3d(this.segmentoActual.StartPoint.X, this.segmentoActual.StartPoint.Y, 0), mobile); return; } else { this.goal = true; return; } } else { //ed.WriteMessage("iNCREMENTANDO!. {0} de {1}\n", segmentoActualIndex + 1, numeroSegmentos); pointActualCurve = 0; segmentoActual = this.ruta.GetLineSegment2dAt(segmentoActualIndex); Lab3.DBMan.UpdateBlockPosition(new Point3d(this.segmentoActual.StartPoint.X, this.segmentoActual.StartPoint.Y, 0), mobile); } } //else //{ //ed.WriteMessage("MOVIENDOSE!. {0} de {1}\n", segmentoActualIndex + 1, numeroSegmentos); //} // } }
private static void addCloudLineSegment(Polyline plCloud, LineSegment2d lineSeg) { var lenCur = 0d; var ptCur = lineSeg.StartPoint; while (lenCur< lineSeg.Length) { if ((lineSeg.Length-lenCur) <100) ptCur = ptCur + lineSeg.Direction * (lineSeg.Length-lenCur); else ptCur = ptCur + lineSeg.Direction * 100; plCloud.AddVertexAt(plCloud.NumberOfVertices, ptCur, -1, 0, 0); lenCur +=100; } }