public void Add(Curve2d curve) { foreach (Point2F pt in curve.Points) { this.Add(pt); } }
public static Curve ConnectCurve(Curve2d C1, Curve2d C2) { var sp1 = C1.StartPoint; var ep1 = C1.EndPoint; var sp2 = C2.StartPoint; var ep2 = C2.EndPoint; var SP = new Point2d(); var EP = new Point2d(); var distance = C1.GetDistanceTo(C2); if (sp1.GetDistanceTo(sp2) > ep1.GetDistanceTo(sp2)) { SP = sp1; } else { SP = ep1; } if (sp2.GetDistanceTo(SP) > ep2.GetDistanceTo(SP)) { EP = sp2; } else { EP = sp1; } var curve = CreateLine(ToPoint3D(SP), ToPoint3D(EP)) as Curve; return(curve); }
/// <summary> /// Initializes a new instance of the <see cref="ConstructionRow"/> class. /// </summary> /// <param name="segment">The segment taken from a polyline.</param> /// <param name="index">The vertex index.</param> /// <param name="cumulativeDistance">The cumulative distance.</param> public ConstructionRow(Curve2d segment, int index, Double cumulativeDistance = 0) { this.Segment = segment; this.Start = segment.StartPoint; this.End = segment.EndPoint; this.Index = index; this.Angle = new Angle(this.Start, this.End); }
public override Vector2 Tangent(float t) { var tx = Curve2d.TangentQuadraticBezier(t, v0.x, v1.x, v2.x); var ty = Curve2d.TangentQuadraticBezier(t, v0.y, v1.y, v2.y); // returns unit vector var tangent = new Vector2(tx, ty); tangent.Normalize(); return(tangent); }
/// <summary> 将三维多段线投影到XY平面上,以转换为二维多段线 </summary> /// <param name="pl"></param> /// <returns></returns> public static CompositeCurve2d Get2dCurve(this Polyline pl) { LineSegment2d seg2d; var seg2ds = new Curve2d[pl.NumberOfVertices - 1]; for (int i = 0; i < pl.NumberOfVertices - 1; i++) { seg2d = pl.GetLineSegment2dAt(i); seg2ds[i] = (seg2d); } return(new CompositeCurve2d(seg2ds)); }
/// <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 PointOnCurve2d GetSplitPt(CivilDB.Structure str, bool start) { Curve2d strPosCurve = StructurePosCurve(str); CurveCurveIntersector2d intersector = new CurveCurveIntersector2d(PositionCurve, strPosCurve); if (intersector.NumberOfIntersectionPoints > 0) { intersector.OrderWithRegardsTo1(); //взять точку пересечения, которая имеет имеет наибольший параметр PositionCurve для начальной точки //и наименьший для конечной точки return(start ? intersector.GetPointOnCurve1(intersector.NumberOfIntersectionPoints - 1) : intersector.GetPointOnCurve1(0)); } return(null); }
public override Math.Vector2 InterpolatedPoint(float t) { var point = (points.Count - 1) * t; var intPoint = Mathf.Floor(point); var weight = point - intPoint; var c = new int[] { intPoint == 0 ? intPoint : intPoint - 1, intPoint, intPoint > points.Count - 2 ? points.Count - 1 : intPoint + 1, intPoint > points.Count - 3 ? points.Count - 1 : intPoint + 2, }; var x = Curve2d.InterpolateCatmullRom(points[c[0]].x, points[c[1]].x, points[c[2]].x, points[c[3]].x, weight); var y = Curve2d.InterpolateCatmullRom(points[c[0]].y, points[c[1]].y, points[c[2]].y, points[c[3]].y, weight); return(new Vector2(x, y)); }
private void CreateRectangle(Curve2d C1, List <Curve2d> Cs) { var C2 = Cs.First(); var sp1 = C1.StartPoint; var ep1 = C1.EndPoint; var Ps1 = new List <Point2d> { sp1, ep1 }; var sp2 = C2.StartPoint; var ep2 = C2.EndPoint; var Ps2 = new List <Point2d> { sp2, ep2 }; var Ps = from p1 in Ps1 from p2 in Ps2 let d = p1.GetDistanceTo(p2) orderby d descending select new List <Point2d> { p1, p2 }; if (Ps.Any()) { var Points = Ps.First(); var Vec1 = CADUtil.GetVector(C1); var Vec2 = CADUtil.GetVector(Points[0], Points[1]); if (Vec1.GetAngleTo(Vec2) > Math.PI / 2) { Vec1 = -Vec1; } double Ang = Math.Abs(Vec1.GetAngleTo(Vec2)); var P1 = CADUtil.ToPoint3D(Points[0]); var P2 = CADUtil.ToPoint3D(Points[1]); CADUtil.CreateRectangle(P1, P2, Vec1, Ang); } }
/// <summary> /// Единообразное представление границы штриховки в виде набора некомпозитных кривых /// </summary> /// <param name="hl"></param> /// <returns></returns> public static List <Curve2d> GetHatchLoopCurves(HatchLoop hl) { BulgeVertexCollection bvc = hl.Polyline; Curve2dCollection cc = hl.Curves; //Перевод в общий набор Curve2d List <Curve2d> curves = new List <Curve2d>(); if (bvc != null && bvc.Count > 0) { Point2d?prevPt = null; double prevBulge = 0; Action <BulgeVertex> action = new Action <BulgeVertex>(bv => { if (prevPt != null) { Curve2d c = (prevBulge == 0 ? (Curve2d)(new LineSegment2d(prevPt.Value, bv.Vertex)) : (Curve2d)(new CircularArc2d(prevPt.Value, bv.Vertex, prevBulge, false))); curves.Add(c); } prevPt = bv.Vertex; prevBulge = bv.Bulge; }); foreach (BulgeVertex bv in bvc) { action(bv); } foreach (BulgeVertex bv in bvc)//добавление замыкающего сегмента полилинии { action(bv); break; } } else if (cc != null && cc.Count > 0) { foreach (Curve2d c in cc) { curves.Add(c); } } return(curves); }
/// <summary> /// 중심점 구하기 /// </summary> /// <param name="C"></param> /// <returns></returns> public static Point2d GetCenterP(Curve2d C) { return(GetCenterP(C.StartPoint, C.EndPoint)); }
public static double GetHatchArea([NotNull] this Hatch hatch) { double area = 0; try { area = hatch.Area; } catch { var nLoop = hatch.NumberOfLoops; for (var i = 0; i < nLoop; i++) { double looparea = 0; var loopType = (int)hatch.LoopTypeAt(i); if ((loopType & (int)HatchLoopTypes.Polyline) > 0) { var hatchLoop = hatch.GetLoopAt(i); var bulgeVertex = hatchLoop.Polyline; using var pPoly = new Polyline(bulgeVertex.Count); for (var j = 0; j < bulgeVertex.Count; j++) { pPoly.AddVertexAt(j, bulgeVertex[j].Vertex, bulgeVertex[j].Bulge, 0, 0); } pPoly.Closed = (loopType & (int)HatchLoopTypes.NotClosed) == 0; looparea = pPoly.Area; if ((loopType & (int)HatchLoopTypes.External) > 0) { area += Math.Abs(looparea); } else { area -= Math.Abs(looparea); } } else { var hatchLoop = hatch.GetLoopAt(i); var cur2ds = new Curve2d[hatchLoop.Curves.Count]; hatchLoop.Curves.CopyTo(cur2ds, 0); using var compCurve = new CompositeCurve2d(cur2ds); var interval = compCurve.GetInterval(); double dMin = interval.GetBounds()[0], dMax = interval.GetBounds()[1]; if (Math.Abs(dMax - dMin) > 1e-6) { try { looparea = compCurve.GetArea(dMin, dMax); if ((loopType & (int)HatchLoopTypes.External) > 0) { area += Math.Abs(looparea); } else { area -= Math.Abs(looparea); } } catch { // Разбиваем кривую на 1000000 точек. Надеюсь, что такой точности // будет достаточно. var pts = compCurve.GetSamplePoints(1000); var np = pts.Length; for (var j = 0; j < np; j++) { looparea += 0.5 * pts[j].X * (pts[(j + 1) % np].Y - pts[(j + np - 1) % np].Y); } if ((loopType & (int)HatchLoopTypes.External) > 0) { area += Math.Abs(looparea); } else { area -= Math.Abs(looparea); } } } } } } return(Math.Abs(area)); }
/// <summary> /// Curve2d의 벡터 /// </summary> /// <param name="C"></param> /// <returns></returns> public static Vector2d Get(Curve2d C) { return(Get(C.StartPoint, C.EndPoint)); }
public static Vector2d GetVector(Curve2d curve) { return(GetVector(curve.StartPoint, curve.EndPoint)); }