private IList <float[]> ArcToLines(PathItem item) { IList <float> numbers = item.Coordinates; EllipseArc ellipse = EllipseArc.CreateEllipseArc(numbers[7], numbers[8], numbers[5], numbers[6], numbers[0], numbers[1], numbers[4], numbers[3]); IList <float[]> newCoordinates = PdfContentByte.BezierArc(ellipse.Cx - numbers[0], ellipse.Cy - numbers[1], ellipse.Cx + numbers[0], ellipse.Cy + numbers[1], ellipse.StartAng, ellipse.Extend); IList <float[]> result = new List <float[]>(); if (newCoordinates.Count == 0) { return(result); } float[] pt = newCoordinates[0]; float x0 = pt[0]; float y0 = pt[1]; for (int k = 0; k < newCoordinates.Count; ++k) { pt = newCoordinates[k]; foreach (float[] point in BezierCurveToLines(x0, y0, pt[2], pt[3], pt[4], pt[5], pt[6], pt[7], true)) { result.Add(point); } x0 = pt[6]; y0 = pt[7]; } return(result); }
public void EllipseArc_Basic() { var o = Point.ByCoordinates(1, 2, 3); var n = Vector.ByCoordinates(2, 3, 4, true); var pl = Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(o, n); var ellipseArc = EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, 10, 5, 45, 90); var revitCurve = ellipseArc.ToRevitType(); Assert.NotNull(revitCurve); Assert.IsAssignableFrom <Autodesk.Revit.DB.Ellipse>(revitCurve); var revitEllipse = (Autodesk.Revit.DB.Ellipse)revitCurve; revitEllipse.GetEndParameter(0).ToDegrees().AssertShouldBeApproximately(ellipseArc.StartAngle); revitEllipse.GetEndParameter(1).ToDegrees().AssertShouldBeApproximately(ellipseArc.StartAngle + ellipseArc.SweepAngle); revitEllipse.GetEndPoint(0).AssertShouldBeApproximately(ellipseArc.StartPoint); revitEllipse.GetEndPoint(1).AssertShouldBeApproximately(ellipseArc.EndPoint); revitEllipse.Length.AssertShouldBeApproximately(ellipseArc.Length); // ClosestPointTo fails in ProtoGeometry var tessPts = revitEllipse.Tessellate(); //assert the tesselation is very close to original curve //what's the best tolerance to use here? foreach (var pt in tessPts) { var closestPt = ellipseArc.GetClosestPoint(pt.ToPoint()); Assert.Less(closestPt.DistanceTo(pt.ToPoint()), 1e-6); } }
/// <summary> /// DS EllipsArc to SpeckleCurve????? /// </summary> /// <param name="arc"></param> /// <returns></returns> public static SpeckleObject ToSpeckle(this EllipseArc arc) { //EllipseArcs as NurbsCurves using (NurbsCurve nurbsCurve = arc.ToNurbsCurve()) { return(nurbsCurve.ToSpeckle()); } }
public static EllipseArc CreateEllipseArc(Drawing drawing, IList <IFigure> foundDependencies) { var result = new EllipseArc() { Drawing = drawing, Dependencies = foundDependencies }; return(result); }
/// <summary> /// DS EllipsArc to SpeckleCurve????? /// </summary> /// <param name="arc"></param> /// <returns></returns> public static SpeckleObject ToSpeckle(this EllipseArc arc) { //EllipseArcs as NurbsCurves using (NurbsCurve nurbsCurve = arc.ToNurbsCurve()) { var nurbs = nurbsCurve.ToSpeckle(); nurbs.Properties = arc.GetSpeckleProperties(); return(nurbs); } }
/// <summary> /// DS EllipseArc to Speckle Ellipse /// </summary> /// <param name="arc"></param> /// <returns></returns> public Ellipse EllipseToSpeckle(EllipseArc arc) { var ellipArc = new Ellipse( PlaneToSpeckle(arc.Plane), arc.MajorAxis.Length, arc.MinorAxis.Length, new Interval(0, 2 * Math.PI), new Interval(arc.StartAngle, arc.StartAngle + arc.SweepAngle), ModelUnits); CopyProperties(ellipArc, arc); return(ellipArc); }
private IEnumerable <Point> ArcPointsConverter(Segment segment, double eps) { EllipseArc arc = (EllipseArc)segment; //какая часть периметра задействована double part = Math.Abs(arc.EndRad - arc.BegRad) / (2 * Math.PI); //сколько реально длины периметра задействовано part *= PerimetreOfEllipse(arc.A, arc.B); //сколько отрезков part = part / eps; List <Point> result = new List <Point>(); double x, y, t = 0; for (int i = 0; i < (int)part; i++) { x = arc.A * Math.Cos(t) + arc.Center.X; y = arc.Center.Y; if (arc.Beg.X < arc.End.X) { y += arc.B * Math.Sin(t); } else { y -= arc.B * Math.Sin(t); } result.Add(new Point(x, y)); t += Math.PI / part; } double cos = Math.Cos(Math.PI * arc.RotAngle / 180); double sin = Math.Sin(Math.PI * arc.RotAngle / 180); foreach (Point point in result) { point.X = point.X * cos - point.Y * sin; point.Y = point.X * sin + point.Y * cos; } if (arc.Beg.X < arc.End.X) { result.Add(arc.Beg); result.RemoveAt(0); result.Reverse(); } return(result); }
private void DrawArc(PdfContentByte cb, IList <float> numbers) { EllipseArc ellipse = EllipseArc.CreateEllipseArc(numbers[7], numbers[8], numbers[5], numbers[6], numbers[0], numbers[1], numbers[4], numbers[3]); cb.SetColorFill(BaseColor.ORANGE); cb.Rectangle(numbers[7], numbers[8], 2, 2); //p1 cb.Fill(); cb.SetColorFill(BaseColor.GREEN); cb.Rectangle(numbers[5], numbers[6], 2, 2); //p2 cb.Fill(); cb.Arc(ellipse.Cx - numbers[0], ellipse.Cy - numbers[1], ellipse.Cx + numbers[0], ellipse.Cy + numbers[1], ellipse.StartAng, ellipse.Extend); }
/// <summary> /// DS EllipseArc to Speckle Ellipse /// </summary> /// <param name="arc"></param> /// <returns></returns> public Ellipse EllipseToSpeckle(EllipseArc arc, string units = null) { var u = units ?? ModelUnits; var ellipArc = new Ellipse( PlaneToSpeckle(arc.Plane, u), arc.MajorAxis.Length, arc.MinorAxis.Length, new Interval(0, 2 * Math.PI), new Interval(arc.StartAngle, arc.StartAngle + arc.SweepAngle), u); CopyProperties(ellipArc, arc); ellipArc.length = arc.Length; ellipArc.bbox = BoxToSpeckle(arc.BoundingBox.ToCuboid(), u); return(ellipArc); }
private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv) { var isFullEllipse = !crv.IsBound || Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2 * Math.PI) < 1e-6; if (isFullEllipse) { return (Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors( crv.Center.ToPoint(false), (crv.XDirection * crv.RadiusX).ToVector(false), (crv.YDirection * crv.RadiusY).ToVector(false))); } // We need to define the major and minor axis as the curve // will be trimmed starting from the major axis (not the xaxis) var major = Math.Max(crv.RadiusX, crv.RadiusY); var minor = Math.Min(crv.RadiusX, crv.RadiusY); Vector majorAxis; Vector minorAxis; double startParam; var span = Math.Abs(crv.GetEndParameter(0) - crv.GetEndParameter(1)).ToDegrees(); if (crv.RadiusX > crv.RadiusY) { majorAxis = crv.XDirection.ToVector(); minorAxis = crv.YDirection.ToVector(); startParam = crv.GetEndParameter(0).ToDegrees(); } else { majorAxis = crv.YDirection.ToVector().Reverse(); minorAxis = crv.XDirection.ToVector(); startParam = crv.GetEndParameter(0).ToDegrees() + 90; } using (var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(false), majorAxis, minorAxis)) { return(EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, major, minor, startParam, span)); } }
private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv) { var isComplete = !crv.IsBound || Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2 * Math.PI) < 1e-6; if (!isComplete) { var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(), crv.XDirection.ToVector(), crv.YDirection.ToVector()); var s = crv.GetEndParameter(0).ToDegrees(); var e = crv.GetEndParameter(1).ToDegrees(); return(EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, crv.RadiusX, crv.RadiusY, s, e - s)); } return(Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors(crv.Center.ToPoint(), (crv.XDirection * crv.RadiusX).ToVector(), (crv.YDirection * crv.RadiusY).ToVector())); }
private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv) { var isFullEllipse = !crv.IsBound || Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2 * Math.PI) < 1e-6; if (isFullEllipse) { return (Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors( crv.Center.ToPoint(false), (crv.XDirection * crv.RadiusX).ToVector(false), (crv.YDirection * crv.RadiusY).ToVector(false))); } double startParam; var span = Math.Abs(crv.GetEndParameter(0) - crv.GetEndParameter(1)).ToDegrees(); startParam = crv.GetEndParameter(0).ToDegrees(); using (var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(false), crv.XDirection.ToVector(), crv.YDirection.ToVector())) { return(EllipseArc.ByPlaneRadiiAngles(pl, crv.RadiusX, crv.RadiusY, startParam, span)); } }
protected override (Curve boundary, List <Curve> holes) CreateBaseCurves() { Curve boundary = null; Point[] points; if (IsCurved) { var holes = new List <Curve>(); var boundaryCurves = new List <Curve>(); var arcHeight = Math.Min(Length, Width / 2); using (Plane arcCenter = Plane.ByOriginNormal( Point.ByCoordinates(Width / 2, arcHeight), Vector.ZAxis())) { boundaryCurves.Add(EllipseArc.ByPlaneRadiiAngles(arcCenter, Width / 2, arcHeight, 180, 180)); if (UsesDepth) { if (arcHeight < Length) { // Top of U has straight parts. points = new[] { Point.ByCoordinates(Width, arcHeight), Point.ByCoordinates(Width, Length), Point.ByCoordinates(Width - Depth, Length), Point.ByCoordinates(Width - Depth, arcHeight) }; boundaryCurves.Add(PolyCurve.ByPoints(points)); points.ForEach(p => p.Dispose()); } else { points = new[] { Point.ByCoordinates(Width, Length), Point.ByCoordinates(Width - Depth, Length) }; // Top of U has no straight parts. boundaryCurves.Add(Line.ByStartPointEndPoint(points[0], points[1])); points.ForEach(p => p.Dispose()); } boundaryCurves.Add(EllipseArc.ByPlaneRadiiAngles(arcCenter, (Width / 2) - Depth, arcHeight - Depth, 0, -180)); if (arcHeight < Length) { // Top of U has straight parts. points = new[] { Point.ByCoordinates(Depth, arcHeight), Point.ByCoordinates(Depth, Length), Point.ByCoordinates(0, Length), Point.ByCoordinates(0, arcHeight) }; boundaryCurves.Add(PolyCurve.ByPoints(points)); points.ForEach(p => p.Dispose()); } else { // Top of U has no straight parts. points = new[] { Point.ByCoordinates(Depth, Length), Point.ByCoordinates(0, Length) }; boundaryCurves.Add(Line.ByStartPointEndPoint(points[0], points[1])); points.ForEach(p => p.Dispose()); } } else { // U has no interior. if (arcHeight < Length) { points = new[] { Point.ByCoordinates(Width, arcHeight), Point.ByCoordinates(Width, Length), Point.ByCoordinates(0, Length), Point.ByCoordinates(0, arcHeight) }; boundaryCurves.Add(PolyCurve.ByPoints(points)); points.ForEach(p => p.Dispose()); } else { points = new[] { Point.ByCoordinates(Width, Length), Point.ByCoordinates(0, Length) }; boundaryCurves.Add(Line.ByStartPointEndPoint(points[0], points[1])); points.ForEach(p => p.Dispose()); } } } boundary = PolyCurve.ByJoinedCurves(boundaryCurves); } else { // Straight U if (UsesDepth) { points = new[] { Point.ByCoordinates(0, 0), Point.ByCoordinates(Width, 0), Point.ByCoordinates(Width, Length), Point.ByCoordinates(Width - Depth, Length), Point.ByCoordinates(Width - Depth, Depth), Point.ByCoordinates(Depth, Depth), Point.ByCoordinates(Depth, Length), Point.ByCoordinates(0, Length) }; boundary = PolyCurve.ByPoints(points, connectLastToFirst: true); points.ForEach(p => p.Dispose()); } else { // Solid straight U (rectangle) points = new[] { Point.ByCoordinates(0, 0), Point.ByCoordinates(Width, 0), Point.ByCoordinates(Width, Length), Point.ByCoordinates(0, Length) }; boundary = PolyCurve.ByPoints(points, connectLastToFirst: true); points.ForEach(p => p.Dispose()); } } return(boundary, default); }
protected override (Curve boundary, List <Curve> holes) CreateBaseCurves() { // The D is pointing "down" so that it matches with the U. var holes = new List <Curve>(); var boundaryCurves = new List <Curve>(); var arcHeight = Math.Min( Length - (UsesDepth ? Depth : 0), Width / 2); Point[] points; if (IsCurved) { Plane arcCenter = null; using (var point = Point.ByCoordinates(Width / 2, arcHeight)) using (var zAxis = Vector.ZAxis()) { arcCenter = Plane.ByOriginNormal(point, zAxis); } boundaryCurves.Add(EllipseArc.ByPlaneRadiiAngles(arcCenter, Width / 2, arcHeight, 180, 180)); if (arcHeight < Length) { points = new[] { Point.ByCoordinates(Width, arcHeight), Point.ByCoordinates(Width, Length), Point.ByCoordinates(0, Length), Point.ByCoordinates(0, arcHeight) }; // Outside of D has a square back. boundaryCurves.Add(PolyCurve.ByPoints(points)); points.ForEach(p => p.Dispose()); } else { points = new[] { Point.ByCoordinates(Width, Length), Point.ByCoordinates(0, Length) }; // Outside of D is half an ellipse (or circle). boundaryCurves.Add(Line.ByStartPointEndPoint(points[0], points[1])); points.ForEach(p => p.Dispose()); } if (UsesDepth) { var curves = new List <Curve> { EllipseArc.ByPlaneRadiiAngles(arcCenter, (Width / 2) - Depth, arcHeight - Depth, 0, -180) }; if (arcHeight < Length - Depth) { points = new[] { Point.ByCoordinates(Depth, arcHeight), Point.ByCoordinates(Depth, Length - Depth), Point.ByCoordinates(Width - Depth, Length - Depth), Point.ByCoordinates(Width - Depth, arcHeight) }; curves.Add(PolyCurve.ByPoints(points)); points.ForEach(p => p.Dispose()); } else { points = new[] { Point.ByCoordinates(Depth, arcHeight), Point.ByCoordinates(Width - Depth, arcHeight) }; curves.Add(Line.ByStartPointEndPoint(points[0], points[1])); points.ForEach(p => p.Dispose()); } holes.Add(PolyCurve.ByJoinedCurves(curves)); curves.ForEach(x => x.Dispose()); } arcCenter.Dispose(); } else { // Faceted D. double baseWidth = Width * Math.Tan(Math.PI / 8); double sideWidth = baseWidth * arcHeight / (2 * Width); points = new[] { Point.ByCoordinates(Width, Length), Point.ByCoordinates(0, Length), Point.ByCoordinates(0, arcHeight - sideWidth), Point.ByCoordinates((Width - baseWidth) / 2, 0), Point.ByCoordinates((Width + baseWidth) / 2, 0), Point.ByCoordinates(Width, arcHeight - sideWidth) }; boundaryCurves.Add(PolyCurve.ByPoints(points, connectLastToFirst: true)); points.ForEach(p => p.Dispose()); if (UsesDepth) { double angleA = Math.Atan2(2 * (arcHeight - sideWidth), Width - baseWidth); double offsetBaseWidth = baseWidth - (2 * Depth / Math.Tan((Math.PI - angleA) / 2)); double offsetSideWidth = sideWidth - (Depth / Math.Tan((angleA / 2) + (Math.PI / 4))); points = new[] { Point.ByCoordinates(Width - Depth, Length - Depth), Point.ByCoordinates(Width - Depth, arcHeight - offsetSideWidth), Point.ByCoordinates((Width + offsetBaseWidth) / 2, Depth), Point.ByCoordinates((Width - offsetBaseWidth) / 2, Depth), Point.ByCoordinates(Depth, arcHeight - offsetSideWidth), Point.ByCoordinates(Depth, Length - Depth) }; holes.Add(PolyCurve.ByPoints(points, connectLastToFirst: true)); points.ForEach(p => p.Dispose()); } } var boundary = PolyCurve.ByJoinedCurves(boundaryCurves); return(boundary, holes); }