Get Point Along Curve

Get Point Along Curve

BrentBurgess1980
Collaborator Collaborator
1,336 Views
2 Replies
Message 1 of 3

Get Point Along Curve

BrentBurgess1980
Collaborator
Collaborator

Hey All,

 

I am developing a tool that will allow a user to select a curve, and dump out the points at given intervals along said curve.

 

This works well for 2D objects.

 

If I have a line from 0,0,0 to 10,0,1

 

it outpus

0, 0, 0

0.9950, 0, 0.0995

1.9901, 0, 0.1990

 

What I want it to output is the point at the interval (2D plane, with the elevation)

0, 0, 0

1, 0, 0.1

2, 0, 0.2

etc

 

Is there a way a function I can use that would allow this, or do I need to write my own function?

 

I hope that made sense.

 

Cheers

 

Brent

 

0 Likes
1,337 Views
2 Replies
Replies (2)
Message 2 of 3

Alexander.Rivilis
Mentor
Mentor

BrentBurgess1980 wrote:

Is there a way a function I can use that would allow this, or do I need to write my own function?


You have to write own function.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 3 of 3

Hallex
Advisor
Advisor

Hi Brent

You can use virtual plane to get the points, see quick example,

Im using existing line for test but you can create LineSegment3d

or CircularArc3d for your polyline segments instead, but way would be the same:

        [CommandMethod("ldiv")]
        public void testLineDivisions()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line: ");
            peo.SetRejectMessage("Only a Line !");
            peo.AddAllowedClass(typeof(Line), false);
            PromptEntityResult per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK) return;
            ObjectId lid = per.ObjectId;

            PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter step: ");
            pdo.AllowNone = true;
            pdo.UseDefaultValue = true;
            pdo.DefaultValue = 1.0;

            PromptDoubleResult res;
            res = ed.GetDouble(pdo);
            if (res.Status != PromptStatus.OK) return;
            double step = res.Value;

            ed.WriteMessage("\nStep entered:\t{0}\n", step);
            Point3d pt;
            Point3d tmp;
            using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                Entity ent = tr.GetObject(lid, OpenMode.ForWrite) as Entity;
                if (ent == null) return;
                Line ln = ent as Line;
                if (ln == null) return;
                Line3d lc = new Line3d(new Point3d(0, 0, 0), new Point3d(10, 0, 1));// current line
                Line3d lx = new Line3d(new Point3d(0, 0, 0), new Point3d(10, 0, 0));// line along x axis
                Plane plan = new Plane();
                int i = 0;
                for (double d = 0.1; d < 1.0; d += 0.1)
                {
                    pt = lx.EvaluatePoint(d);
                    plan = new Plane(pt, Vector3d.XAxis);
                    tmp = plan.IntersectWith(lc)[0];// get intersection point between the line and virtual plane
                    ed.WriteMessage("\nPoint Number: {0}\tPoint: {1:f3}\n", i + 1, tmp);
                    i++;
                }
                lc.Dispose();
                lx.Dispose();

            }
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes