Author Topic: Curve Functions  (Read 9737 times)

0 Members and 1 Guest are viewing this topic.

wannabe

  • Guest
Curve Functions
« on: June 19, 2009, 07:57:12 AM »
I'm working on a small application that will get points at specified locations along a polyline utilising the functionality available in the abstract Curve class.

At the moment I'm not having any luck in finding a method that will get points along my polyling ignoring its depth value. Rather than creating a 2d version of my 3D polyline, is there a method that will treat my 3D poly as 2D and ignore all the Z values?

Cheers

xsfhlzh

  • Guest
Re: Curve Functions
« Reply #1 on: June 20, 2009, 04:53:44 AM »
Use this method

GetOrthoProjectedCurve(Autodesk.AutoCAD.Geometry.Plane planeToProjectOn)

wannabe

  • Guest
Re: Curve Functions
« Reply #2 on: June 20, 2009, 08:35:00 AM »
Use this method

GetOrthoProjectedCurve(Autodesk.AutoCAD.Geometry.Plane planeToProjectOn)


Will do. Thanks.

wannabe

  • Guest
Re: Curve Functions
« Reply #3 on: June 21, 2009, 10:02:14 AM »
Use this method

GetOrthoProjectedCurve(Autodesk.AutoCAD.Geometry.Plane planeToProjectOn)


If my X axis is running horizontal, my Y running vertical and I want to select a polyline and convert it to a 2D version how do I configure this method? So far it's hitting me with errors each time.

Cheers

wannabe

  • Guest
Re: Curve Functions
« Reply #4 on: June 21, 2009, 10:10:47 AM »
Actually ignore my last post.

For anyone else's potential benefit, this method will only return a 2D representation if you pass it an actual 3D polyline. My testing was based on a 2D which was giving me the errors.


SEANT

  • Bull Frog
  • Posts: 345
Re: Curve Functions
« Reply #5 on: June 21, 2009, 10:41:18 AM »
Actually ignore my last post.

For anyone else's potential benefit, this method will only return a 2D representation if you pass it an actual 3D polyline. My testing was based on a 2D which was giving me the errors.



This unfortunately means processing poly”curves” with arcs (bulges) is not possible with those Database Curve methods.  It was one of the reasons I used that DBCurve to GeometryCurve Helper class.  The Geometry namespace CompositeCurve can be projected even if it contains arcs.
Sean Tessier
AutoCAD 2016 Mechanical

wannabe

  • Guest
Re: Curve Functions
« Reply #6 on: June 21, 2009, 11:09:14 AM »
Actually ignore my last post.

For anyone else's potential benefit, this method will only return a 2D representation if you pass it an actual 3D polyline. My testing was based on a 2D which was giving me the errors.



This unfortunately means processing poly”curves” with arcs (bulges) is not possible with those Database Curve methods.  It was one of the reasons I used that DBCurve to GeometryCurve Helper class.  The Geometry namespace CompositeCurve can be projected even if it contains arcs.

Do you have a snippet of code I could take a look at or a reference to some, please?


xsfhlzh

  • Guest
Re: Curve Functions
« Reply #7 on: June 21, 2009, 08:25:43 PM »
Code: [Select]
        public static Autodesk.AutoCAD.DatabaseServices.Polyline ToPolyline(CompositeCurve3d cc3d)
        {
            Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();
            pl.Elevation = cc3d.StartPoint[2];
            Plane plane = pl.GetPlane();
            Point2d endver = Point2d.Origin;
            int i = 0;
            foreach (Curve3d c3d in cc3d.GetCurves())
            {
                if (c3d is CircularArc3d)
                {
                    CircularArc3d ca3d = (CircularArc3d)c3d;
                    double b = Math.Tan(0.25 * (ca3d.EndAngle - ca3d.StartAngle)) * ca3d.Normal[2];
                    pl.AddVertexAt(i, c3d.StartPoint.Convert2d(plane), b, 0, 0);
                    endver = c3d.EndPoint.Convert2d(plane);
                }
                else
                {
                    pl.AddVertexAt(i, c3d.StartPoint.Convert2d(plane), 0, 0, 0);
                    endver = c3d.EndPoint.Convert2d(plane);
                }
                i++;
            }
            pl.AddVertexAt(i, endver, 0, 0, 0);
            return pl;
        }

        public static CompositeCurve3d ToCompositeCurve3d(Autodesk.AutoCAD.DatabaseServices.Polyline pl)
        {
            List<Curve3d> c3ds = new List<Curve3d>();

            for (int i = 0; i < pl.NumberOfVertices; i++)
            {
                switch (pl.GetSegmentType(i))
                {
                    case SegmentType.Line:
                        c3ds.Add(pl.GetLineSegmentAt(i));
                        break;
                    case SegmentType.Arc:
                        c3ds.Add(pl.GetArcSegmentAt(i));
                        break;
                    default:
                        break;
                }

            }
            return new CompositeCurve3d(c3ds.ToArray());
        }


        [CommandMethod("t8")]
        public static void Test8()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();
                pl.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                pl.AddVertexAt(1, new Point2d(10, 0), 0.5, 0, 0);
                pl.AddVertexAt(2, new Point2d(20, 0), 0, 0, 0);
                pl.Elevation = 10;
                CompositeCurve3d cc3d = ToCompositeCurve3d(pl);
                cc3d = (CompositeCurve3d)cc3d.GetOrthoProjectEntity(new Plane());

                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                pl = ToPolyline(cc3d);
                btr.AppendEntity(pl);
                tr.AddNewlyCreatedDBObject(pl, true);
                tr.Commit();
            }

SEANT

  • Bull Frog
  • Posts: 345
Re: Curve Functions
« Reply #8 on: June 21, 2009, 09:11:34 PM »
Actually ignore my last post.

For anyone else's potential benefit, this method will only return a 2D representation if you pass it an actual 3D polyline. My testing was based on a 2D which was giving me the errors.



This unfortunately means processing poly”curves” with arcs (bulges) is not possible with those Database Curve methods.  It was one of the reasons I used that DBCurve to GeometryCurve Helper class.  The Geometry namespace CompositeCurve can be projected even if it contains arcs.

Do you have a snippet of code I could take a look at or a reference to some, please?



The thread over at CadTutor (post 22) has a start (similar to the process posted by xsfhlzh above).  I have an updated version that includes a few more curve types.  I’ll post the update when I get a chance.

http://www.cadtutor.net/forum/showthread.php?t=33523
Sean Tessier
AutoCAD 2016 Mechanical

wannabe

  • Guest
Re: Curve Functions
« Reply #9 on: June 22, 2009, 05:02:07 AM »
Excellent, as always.

SEANT

  • Bull Frog
  • Posts: 345
Re: Curve Functions
« Reply #10 on: June 22, 2009, 07:35:06 AM »
This version could still use some refinement.  Quadratic- and CubicFit Polys are still not implemented, nor is the error checking mechanism finalized. 

Eventually I’d like to incorporate a similar process for 3d entities such as the primitives Sphere, Cylinder, Torus, etc. 


Edit: Outdated code removed.
« Last Edit: July 13, 2009, 06:14:40 AM by SEANT »
Sean Tessier
AutoCAD 2016 Mechanical

xsfhlzh

  • Guest
Re: Curve Functions
« Reply #11 on: June 22, 2009, 10:59:08 AM »
This version could still use some refinement.  Quadratic- and CubicFit Polys are still not implemented, nor is the error checking mechanism finalized. 

Eventually I’d like to incorporate a similar process for 3d entities such as the primitives Sphere, Cylinder, Torus, etc. 


EllipticalArc3d's Angle is Ellipse's Param,

Code: [Select]
        public static EllipticalArc3d ToEllipticalArc3d(Ellipse ell)
        {
            return
                new EllipticalArc3d(
                    ell.Center,
                    ell.MajorAxis.GetNormal(),
                    ell.MinorAxis.GetNormal(),
                    ell.MajorRadius,
                    ell.MinorRadius,
                    ell.StartParam,
                    ell.EndParam);

        }

Quadratic- and CubicFit Polys,Convert it to NurbCurve3d

Code: [Select]
        public static NurbCurve3d ToNurbCurve3d(Polyline2d pl2d)
        {
            switch (pl2d.PolyType)
            {
                case Poly2dType.SimplePoly:
                case Poly2dType.FitCurvePoly:
                    Polyline pl = new Polyline();
                    pl.ConvertFrom(pl2d, false);
                    return ToNurbCurve3d(pl);
                default:
                    return ToNurbCurve3d(pl2d.Spline);
            }
        }

SEANT

  • Bull Frog
  • Posts: 345
Re: Curve Functions
« Reply #12 on: June 22, 2009, 05:00:13 PM »
Good catch with the -Angle/-Param switch.  :-)

I have to admit that the EllipticalArc3d is trickier than I first assumed.  After further testing, I’ve found that the Ellipse.MinorRadius is not reliable, and should, instead, be replaced by Ellipse.MajorRadius * Ellipse.RadiusRatio.

With regard to the splined polys:  I wasn’t sure the best way to proceed given that the curve within AutoCAD’s drawing editor is actually straight line segments (driven by SPLINESEGS system variable) inscribed to a control spline.
« Last Edit: June 22, 2009, 05:08:10 PM by SEANT »
Sean Tessier
AutoCAD 2016 Mechanical