Author Topic: Add arc at polyline vertex  (Read 15697 times)

0 Members and 1 Guest are viewing this topic.

krkec

  • Guest
Add arc at polyline vertex
« on: December 23, 2012, 08:00:54 AM »
Hi

is there  a way to add arc to every polyline vertex ( I am editing existing polyline). I tried with bulge but I don't understand relation between radius and angle in bulge concept?


Please help me with some hints.


fixo

  • Guest
Re: Add arc at polyline vertex
« Reply #1 on: December 23, 2012, 10:41:50 AM »
You may want this one to create arcs on every segment,
in case you need to create the bulged segments instead,
then use SetBulge method
Code: [Select]
                public static Point3d PolarPoint(Point3d basepoint, double angle, double distance)
                {
                    // credits to Tony Tanzillo
                    return new Point3d(
                    basepoint.X + (distance * Math.Cos(angle)),
                    basepoint.Y + (distance * Math.Sin(angle)),
                    basepoint.Z);
                }
                [CommandMethod("PARC")]
                public void addArcs()
                {

                    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

                    Editor ed = doc.Editor;

                    Database db = doc.Database;

                    Transaction tr = doc.TransactionManager.StartTransaction();

                    using (tr)
                    {
                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                        // prompt for selecting polyline   
                        PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: >>");

                        peo.SetRejectMessage("\nSelect a polyline only >>");

                        peo.AddAllowedClass(typeof(Polyline), false);

                        peo.AllowObjectOnLockedLayer = true;

                        PromptEntityResult res;

                        res = ed.GetEntity(peo);

                        if (res.Status != PromptStatus.OK) return;

                        Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);

                        if (ent == null) return;

                        Polyline pline = (Polyline)ent as Polyline;

                        if (pline == null) return;

                        // get the number of segments   

                        int segments = pline.NumberOfVertices - 1;

                        for (int i = 0; i < segments; i++)
                        {
                            if (pline.GetSegmentType(i) == SegmentType.Arc)

                                continue;

                            // get arc segment on polyline   
                            LineSegment2d lseg = pline.GetLineSegment2dAt(i);

                            // get center   

                            Point2d center = lseg.EvaluatePoint(0.5);
                            // create an Arc   
                          Point2d   p1 = lseg.StartPoint;
                          Point2d p2 = lseg.EndPoint;
                          double ang = lseg.Direction.Angle;
                            Point3d mp = new Point3d((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2,pline.Elevation).TransformBy(Matrix3d.Identity);
                            // get half of hord
                            double cat = lseg.Length / 2.0;
                            // you have soecify radius of an arc here:
                            double rad = lseg.Length * 1.25;// <--    dummy radius for test
                            // get next catet
                            double bcat = Math.Sqrt(rad * rad - cat * cat);

                            Point3d cp = PolarPoint(mp, ang + Math.PI / 2, bcat);

                            Plane plan = new Plane(Point3d.Origin, Vector3d.ZAxis);

                            Point3d sp=new Point3d(p1.X,p1.Y,pline.Elevation);

                            Point3d ep = new Point3d(p2.X, p2.Y, pline.Elevation);

                            // create arc using center radius and both angles, count clockwise from start line to end
                            Arc arc = new Arc(cp, rad, cp.GetVectorTo(sp).AngleOnPlane(plan), cp.GetVectorTo(ep).AngleOnPlane(plan));

                            // add to current space and transaction
                            btr.AppendEntity(arc);

                            tr.AddNewlyCreatedDBObject(arc, true);
             
   
                        }
                        tr.Commit();
                    }

                }

krkec

  • Guest
Re: Add arc at polyline vertex
« Reply #2 on: December 23, 2012, 12:36:20 PM »
Thanks for quick respond.

But it isn't  what I'm looking for. I want to edit existing polyline by inserting arcs of specific radius into vertex point (vertex point is intersection of arc tangents). Something like filleting polylines.

Any idea?


fixo

  • Guest
Re: Add arc at polyline vertex
« Reply #3 on: December 23, 2012, 01:35:23 PM »
So you can try this way
it will should you methods you need,
code create a simple polyline then add
bulge in to one segment,
then you can expand it to your current polyline I hope
 
Code: [Select]
              [CommandMethod("FPL")]
                public void filletPline()
                {
                    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                    Editor ed = doc.Editor;
                    Database db = HostApplicationServices.WorkingDatabase;
                    try
                    {
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                        {
                            Point3dCollection pts = new Point3dCollection();
                            Point3d pt = new Point3d(0, 0, 0);
                            pts.Add(pt);
                            pt = new Point3d(100, 0, 0);
                            pts.Add(pt);
                            pt = new Point3d(100, 50, 0);
                            pts.Add(pt);
                            pt = new Point3d(0, 50, 0);
                            pts.Add(pt);
                            Polyline pol = new Polyline(pts.Count);

                            Matrix3d ucs = ed.CurrentUserCoordinateSystem;
                            Point3d origin = new Point3d(0, 0, 0);
                            Vector3d normal = new Vector3d(0, 0, 1);
                            normal = normal.TransformBy(ucs);
                            Plane plane = new Plane(origin, normal);
                            int j = 0;
                            foreach (Point3d pnt in pts)
                            {
                                Point3d transformedPt = pnt.TransformBy(ucs);
                                pol.AddVertexAt(pol.NumberOfVertices, plane.ParameterOf(transformedPt), 0, 0, 0);
                                pol.SetEndWidthAt(j, 2);
                                pol.SetStartWidthAt(j, 2);
                                j++;
                            }

                            pol.SetBulgeAt(1, Math.PI / 4);
                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                            btr.AppendEntity(pol);
                            tr.AddNewlyCreatedDBObject(pol, true);

                            tr.Commit();
                        }
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception ex)
                    {
                        ed.WriteMessage(ex.StackTrace);
                    }
                }

fixo

  • Guest
Re: Add arc at polyline vertex
« Reply #4 on: December 23, 2012, 02:13:57 PM »
In addition you can use this code too
Code: [Select]
                [DllImport("acad.exe", BestFitMapping = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
                private static extern int acedCmd(System.IntPtr cmd);
                [CommandMethod("FILET")]
                public static void TestFillet()
                {
                    Database db = HostApplicationServices.WorkingDatabase;

                    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

                    Editor ed = doc.Editor;

                    Transaction tr = db.TransactionManager.StartTransaction();

                    using (tr)
                    {

                        try
                        {
                            // Prompt for the polyline to revcloud

                            PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline:");

                            peo.SetRejectMessage("\nSelect polyline only");

                            peo.AddAllowedClass(typeof(Polyline), true);

                            PromptEntityResult per = ed.GetEntity(peo);

                            if (per.Status != PromptStatus.OK)
                            {
                                return;
                            }

                            ObjectId fid = per.ObjectId;

                            DBObject obj1 = tr.GetObject(fid, OpenMode.ForWrite);

                            Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("CMDECHO", 0);

                            Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FILLETRAD", 50.0);

                            ResultBuffer buf = new ResultBuffer();

                            buf.Add(new TypedValue(5005, "_FILLET"));

                            buf.Add(new TypedValue(5005, "_P"));

                            buf.Add(new TypedValue(5006, fid));

                            acedCmd(buf.UnmanagedObject);

                            buf.Dispose();

                            Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("CMDECHO", 1);

                            tr.Commit();


                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ex)
                        {
                            ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);

                        }

                    }

                }

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Add arc at polyline vertex
« Reply #5 on: December 23, 2012, 03:05:03 PM »
Hi,

Here's a way using some geometry.

Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.Runtime;
  7. using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
  8.  
  9. [assembly: CommandClass(typeof(PolylineFillet.CommandMethods))]
  10.  
  11. namespace PolylineFillet
  12. {
  13.     public class CommandMethods
  14.     {
  15.         [CommandMethod("Test", CommandFlags.Modal)]
  16.         public void Test()
  17.         {
  18.             Document doc = AcAp.DocumentManager.MdiActiveDocument;
  19.             Database db = doc.Database;
  20.             Editor ed = doc.Editor;
  21.  
  22.             PromptDistanceOptions pdo = new PromptDistanceOptions("\nFillet radius: ");
  23.             pdo.AllowZero = false;
  24.             pdo.AllowNegative = false;
  25.             PromptDoubleResult pdr = ed.GetDistance(pdo);
  26.             if (pdr.Status != PromptStatus.OK)
  27.                 return;
  28.  
  29.             double radius = pdr.Value;
  30.             PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ");
  31.             peo.SetRejectMessage("Not a polyline.");
  32.             peo.AddAllowedClass(typeof(Polyline), true);
  33.             PromptEntityResult per = ed.GetEntity(peo);
  34.             if (per.Status != PromptStatus.OK)
  35.                 return;
  36.  
  37.             using (Transaction tr = db.TransactionManager.StartTransaction())
  38.             {
  39.                 Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
  40.                 FilletAll(pline, radius);
  41.                 tr.Commit();
  42.             }
  43.         }
  44.  
  45.         private void FilletAll(Polyline pline, double radius)
  46.         {
  47.             int n = pline.Closed ? 1 : 2;
  48.             for (int i = 0; i < pline.NumberOfVertices - n; i++)
  49.                 i += Fillet(pline, radius, i, i + 1);
  50.             if (pline.Closed)
  51.                 Fillet(pline, radius, pline.NumberOfVertices - 1, 0);
  52.         }
  53.  
  54.         private int Fillet(Polyline pline, double radius, int index1, int index2)
  55.         {
  56.             if (pline.GetSegmentType(index1) != SegmentType.Line ||
  57.                 pline.GetSegmentType(index2) != SegmentType.Line)
  58.                 return 0;
  59.             LineSegment2d seg1 = pline.GetLineSegment2dAt(index1);
  60.             LineSegment2d seg2 = pline.GetLineSegment2dAt(index2);
  61.             Vector2d vec1 = seg1.StartPoint - seg1.EndPoint;
  62.             Vector2d vec2 = seg2.EndPoint - seg2.StartPoint;
  63.             double angle = vec1.GetAngleTo(vec2) / 2.0;
  64.             double dist = radius / Math.Tan(angle);
  65.             if (dist > seg1.Length || dist > seg2.Length)
  66.                 return 0;
  67.             Point2d pt1 = seg1.EndPoint.TransformBy(Matrix2d.Displacement(vec1.GetNormal() * dist));
  68.             Point2d pt2 = seg2.StartPoint.TransformBy(Matrix2d.Displacement(vec2.GetNormal() * dist));
  69.             double bulge = Math.Tan((Math.PI / 2.0 - angle) / 2.0);
  70.             if (Clockwise(seg1.StartPoint, seg1.EndPoint, seg2.EndPoint))
  71.                 bulge = -bulge;
  72.             pline.AddVertexAt(index2, pt1, bulge, 0.0, 0.0);
  73.             pline.SetPointAt(index2 + 1, pt2);
  74.             return 1;
  75.         }
  76.  
  77.         private bool Clockwise(Point2d p1, Point2d p2, Point2d p3)
  78.         {
  79.             return ((p2.X - p1.X) * (p3.Y - p1.Y) - (p2.Y - p1.Y) * (p3.X - p1.X)) < 1e-8;
  80.         }
  81.     }
  82. }
  83.  
« Last Edit: December 23, 2012, 04:48:55 PM by gile »
Speaking English as a French Frog

krkec

  • Guest
Re: Add arc at polyline vertex
« Reply #6 on: December 24, 2012, 03:22:09 AM »
thanks guys i am trying it now

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Add arc at polyline vertex
« Reply #7 on: December 24, 2012, 04:38:35 AM »
Hi,

Here's a better (more reusable) implementation:

Testing command
Code - C#: [Select]
  1.     public class CommandMethods
  2.     {
  3.         [CommandMethod("Test", CommandFlags.Modal)]
  4.         public void Test()
  5.         {
  6.             Document doc = AcAp.DocumentManager.MdiActiveDocument;
  7.             Database db = doc.Database;
  8.             Editor ed = doc.Editor;
  9.  
  10.             PromptDistanceOptions pdo = new PromptDistanceOptions("\nFillet radius: ");
  11.             pdo.AllowZero = false;
  12.             pdo.AllowNegative = false;
  13.             PromptDoubleResult pdr = ed.GetDistance(pdo);
  14.             if (pdr.Status != PromptStatus.OK)
  15.                 return;
  16.             double radius = pdr.Value;
  17.  
  18.             PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ");
  19.             peo.SetRejectMessage("Not a polyline.");
  20.             peo.AddAllowedClass(typeof(Polyline), true);
  21.             PromptEntityResult per = ed.GetEntity(peo);
  22.             if (per.Status != PromptStatus.OK)
  23.                 return;
  24.  
  25.             using (Transaction tr = db.TransactionManager.StartTransaction())
  26.             {
  27.                 Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
  28.                 pline.FilletAll(radius);
  29.                 tr.Commit();
  30.             }
  31.         }
  32.     }

Extension methods
Code - C#: [Select]
  1.     static class Extensions
  2.     {
  3.         /// <summary>
  4.         /// Adds an arc (fillet), if able, at each polyline vertex.
  5.         /// </summary>
  6.         /// <param name="pline">The instance to which the method applies.</param>
  7.         /// <param name="radius">The arc radius.</param>
  8.         public static void FilletAll(this Polyline pline, double radius)
  9.         {
  10.             int j = pline.Closed ? 0 : 1;
  11.             for (int i = j; i < pline.NumberOfVertices - j; i++)
  12.             {
  13.                 i += pline.FilletAt(i, radius);
  14.             }
  15.         }
  16.  
  17.         /// <summary>
  18.         /// Adds an arc (fillet) at the specified vertex.
  19.         /// </summary>
  20.         /// <param name="pline">The instance to which the method applies.</param>
  21.         /// <param name="index">The index of the verex.</param>
  22.         /// <param name="radius">The arc radius.</param>
  23.         /// <returns>1 if the operation succeeded, 0 if it failed.</returns>
  24.         public static int FilletAt(this Polyline pline, int index, double radius)
  25.         {
  26.             int prev = index == 0 && pline.Closed ? pline.NumberOfVertices - 1 : index - 1;
  27.             if (pline.GetSegmentType(prev) != SegmentType.Line ||
  28.                 pline.GetSegmentType(index) != SegmentType.Line)
  29.             {
  30.                 return 0;
  31.             }
  32.             LineSegment2d seg1 = pline.GetLineSegment2dAt(prev);
  33.             LineSegment2d seg2 = pline.GetLineSegment2dAt(index);
  34.             Vector2d vec1 = seg1.StartPoint - seg1.EndPoint;
  35.             Vector2d vec2 = seg2.EndPoint - seg2.StartPoint;
  36.             double angle = vec1.GetAngleTo(vec2) / 2.0;
  37.             double dist = radius / Math.Tan(angle);
  38.             if (dist == 0.0 || dist > seg1.Length || dist > seg2.Length)
  39.             {
  40.                 return 0;
  41.             }
  42.             Point2d pt1 = seg1.EndPoint + vec1.GetNormal() * dist;
  43.             Point2d pt2 = seg2.StartPoint + vec2.GetNormal() * dist;
  44.             double bulge = Math.Tan((Math.PI / 2.0 - angle) / 2.0);
  45.             if (Clockwise(seg1.StartPoint, seg1.EndPoint, seg2.EndPoint))
  46.             {
  47.                 bulge = -bulge;
  48.             }
  49.             pline.AddVertexAt(index, pt1, bulge, 0.0, 0.0);
  50.             pline.SetPointAt(index + 1, pt2);
  51.             return 1;
  52.         }
  53.  
  54.         /// <summary>
  55.         /// Evaluates if the points are clockwise.
  56.         /// </summary>
  57.         /// <param name="p1">First point.</param>
  58.         /// <param name="p2">Second point</param>
  59.         /// <param name="p3">Third point</param>
  60.         /// <returns>True if points are clockwise, False otherwise.</returns>
  61.         private static bool Clockwise(Point2d p1, Point2d p2, Point2d p3)
  62.         {
  63.             return ((p2.X - p1.X) * (p3.Y - p1.Y) - (p2.Y - p1.Y) * (p3.X - p1.X)) < 1e-8;
  64.         }
  65.     }

<Edit: added comments>
<Edit: corrected a dysfunction with colinear segments by checkin dist == 0.0>
« Last Edit: October 01, 2017, 03:47:10 AM by gile »
Speaking English as a French Frog

krkec

  • Guest
Re: Add arc at polyline vertex
« Reply #8 on: December 27, 2012, 02:13:12 PM »
 Thanks for response but I have problem with your code gile.
1. First code  I tryed  but it doesnt fillet at all vertex points

2. When I convert second code to vb.net  and copy it to  visual studio  i get thi error

Error   1   'FilletAt' is not a member of 'Autodesk.AutoCAD.DatabaseServices.Polyline'.    on this line --->  i += pline.FilletAt(i, radius) and
Error   2   'FilletAll' is not a member of 'Autodesk.AutoCAD.DatabaseServices.Polyline'.    on this line ---> pline.FilletAll(radius)

what am I doing wrong???


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Add arc at polyline vertex
« Reply #9 on: December 27, 2012, 03:46:35 PM »
With VB, extension methods have to be defined in a module and with a 'System.Runtime.CompilerServices.Extension' attribute.
One other thing: with VB, the 'for' statement does not check the condition at each loop so, to loop for each vertex while adding some new ones, you must use a 'while' statement instead.

VB
Code - vb.net: [Select]
  1.     Module Extensions
  2.  
  3.         ' Adds an arc (fillet) at each polyline vertex, if able.
  4.         <System.Runtime.CompilerServices.Extension> _
  5.         Public Sub FilletAll(pline As Polyline, radius As Double)
  6.             Dim i As Integer = If(pline.Closed, 0, 1)
  7.             While i < If(pline.Closed, pline.NumberOfVertices, pline.NumberOfVertices - 1)
  8.                 i += 1 + pline.FilletAt(i, radius)
  9.             End While
  10.         End Sub
  11.  
  12.         ' Adds an arc (fillet) at the specified vertex. Retuns 1 if the operation succeeded, 0 if it failed.
  13.         <System.Runtime.CompilerServices.Extension> _
  14.         Public Function FilletAt(pline As Polyline, index As Integer, radius As Double) As Integer
  15.             Dim prev As Integer = If(index = 0 AndAlso pline.Closed, pline.NumberOfVertices - 1, index - 1)
  16.             If pline.GetSegmentType(prev) <> SegmentType.Line OrElse _
  17.                 pline.GetSegmentType(index) <> SegmentType.Line Then
  18.                 Return 0
  19.             End If
  20.             Dim seg1 As LineSegment2d = pline.GetLineSegment2dAt(prev)
  21.             Dim seg2 As LineSegment2d = pline.GetLineSegment2dAt(index)
  22.             Dim vec1 As Vector2d = seg1.StartPoint - seg1.EndPoint
  23.             Dim vec2 As Vector2d = seg2.EndPoint - seg2.StartPoint
  24.             Dim angle As Double = (Math.PI - vec1.GetAngleTo(vec2)) / 2.0
  25.             Dim dist As Double = radius * Math.Tan(angle)
  26.             If dist > seg1.Length OrElse dist > seg2.Length Then
  27.                 Return 0
  28.             End If
  29.             Dim pt1 As Point2d = seg1.EndPoint + vec1.GetNormal() * dist
  30.             Dim pt2 As Point2d = seg2.StartPoint + vec2.GetNormal() * dist
  31.             Dim bulge As Double = Math.Tan(angle / 2.0)
  32.             If Clockwise(seg1.StartPoint, seg1.EndPoint, seg2.EndPoint) Then
  33.                 bulge = -bulge
  34.             End If
  35.             pline.AddVertexAt(index, pt1, bulge, 0.0, 0.0)
  36.             pline.SetPointAt(index + 1, pt2)
  37.             Return 1
  38.         End Function
  39.  
  40.         ' Evaluates if the points are clockwise.
  41.         Private Function Clockwise(p1 As Point2d, p2 As Point2d, p3 As Point2d) As Boolean
  42.             Return ((p2.X - p1.X) * (p3.Y - p1.Y) - (p2.Y - p1.Y) * (p3.X - p1.X)) < 0.00000001
  43.         End Function
  44.  
  45.     End Module
Speaking English as a French Frog

krkec

  • Guest
Re: Add arc at polyline vertex
« Reply #10 on: December 27, 2012, 03:55:32 PM »
thank you very very much its working

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Add arc at polyline vertex
« Reply #11 on: December 27, 2012, 04:06:28 PM »
You're welcome krkec, I had fun writing this snippet.

If someone have some interest, here's a F# implementation of these extension methods.

Code - F#: [Select]
  1. // Evaluates if the points are clockwise.
  2. let clockwise (p1: Point2d) (p2: Point2d) (p3: Point2d) =
  3.     ((p2.X - p1.X) * (p3.Y - p1.Y) - (p2.Y - p1.Y) * (p3.X - p1.X)) < 1e-8
  4.  
  5. type Polyline with
  6.     // Adds an arc (fillet) at the specified vertex. Retuns 1 if the operation succeeded, 0 if it failed.
  7.     member pl.FilletAt index radius =
  8.         let prev = (if index = 0 && pl.Closed then pl.NumberOfVertices else index) - 1
  9.         if pl.GetSegmentType(prev) <> SegmentType.Line ||
  10.             pl.GetSegmentType(index) <> SegmentType.Line then
  11.             0
  12.         else
  13.             let seg1 = pl.GetLineSegment2dAt(prev)
  14.             let seg2 = pl.GetLineSegment2dAt(index)
  15.             let vec1 = seg1.StartPoint - seg1.EndPoint
  16.             let vec2 = seg2.EndPoint - seg2.StartPoint
  17.             let angle = (Math.PI - vec1.GetAngleTo(vec2)) / 2.
  18.             let dist = radius * tan(angle)
  19.             if dist > seg1.Length || dist > seg2.Length then
  20.                 0
  21.             else
  22.                 let pt1 = seg1.EndPoint + vec1.GetNormal() * dist
  23.                 let pt2 = seg2.StartPoint + vec2.GetNormal() * dist
  24.                 let mutable bulge = tan(angle / 2.)
  25.                 if clockwise pt1 seg1.EndPoint pt2 then bulge <- -bulge
  26.                 pl.AddVertexAt(index, pt1, bulge, 0., 0.)
  27.                 pl.SetPointAt(index + 1, pt2)
  28.                 1
  29.  
  30.     // Adds an arc (fillet) at each vertex, if able.
  31.     member pl.FilletAll radius =
  32.         let rec loop i =
  33.             if i < pl.NumberOfVertices then
  34.                 loop (i + 1 + pl.FilletAt i radius)
  35.         loop (if pl.Closed then 0 else 1)
Speaking English as a French Frog

krkec

  • Guest
Re: Add arc at polyline vertex
« Reply #12 on: December 27, 2012, 04:43:46 PM »
Thanks i will try this code

can i ask for one more help.

i implemented your code  and added my own

here is my code:
Code: [Select]
Private Sub spoly_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles spoly.Click


        Dim doc As Document = DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim rad As Double = radius.Text
        Dim peo As New PromptEntityOptions(vbLf & "Select a polyline: ")
        peo.SetRejectMessage("Not a polyline.")
        peo.AddAllowedClass(GetType(Polyline), True)
        Dim per As PromptEntityResult = ed.GetEntity(peo)
        If per.Status <> PromptStatus.OK Then
            Return
        End If

        Dim kutevi As New DoubleCollection
        Dim tocke As New Point3dCollection
        Dim duljine As New DoubleCollection
        Using tr As Transaction = db.TransactionManager.StartTransaction()
            Dim pline As Polyline = DirectCast(tr.GetObject(per.ObjectId, OpenMode.ForWrite), Polyline)
            FilletAll(pline, rad)
            For i As Integer = 0 To pline.NumberOfVertices - 1
                If pline.GetSegmentType(i) = SegmentType.Arc Then
                    kutevi.Add(pline.GetArcSegment2dAt(i).EndAngle - pline.GetArcSegment2dAt(i).StartAngle)
                    Dim j As Integer = 1
                    Dim l12d As New LineSegment2d(pline.GetArcSegment2dAt(i).StartPoint, pline.GetArcSegment2dAt(i).EndPoint)
                    Dim vecv2d As Vector2d = (l12d.MidPoint - pline.GetArcSegment2dAt(i).Center)
                    Dim kut2 As Double = vecv2d.Angle
                    Dim x As Double = rad / Math.Cos((pline.GetArcSegment2dAt(i).EndAngle - pline.GetArcSegment2dAt(i).StartAngle) * 0.5)
                    Dim k As Point3d = PolarPoint(pline.GetArcSegmentAt(i).Center, kut2, x)
                    'tocke.Add(k)
                    Dim vl1 As New Line(pline.GetArcSegmentAt(i).StartPoint, k)
                    Dim VL2 As New Line(pline.GetArcSegmentAt(i).EndPoint, k)
                    tocke.Add(VL2.EndPoint)
                    MsgBox("x=" & k.X.ToString & " y=" & k.Y.ToString)
                    draw(HostApplicationServices.WorkingDatabase, vl1)
                    draw(HostApplicationServices.WorkingDatabase, VL2)
                End If
            Next
            tr.Commit()
        End Using
       
    End Sub



problem is with this
I constructed point
Dim k As Point3d = PolarPoint(pline.GetArcSegmentAt(i).Center, kut2, x)
but when I do this MsgBox("x=" & k.X.ToString & " y=" & k.Y.ToString)
I get x=0 y = -2.35 or some thing simular wich is not true

line vl1 i vl2 uses k point and its ok  but for anything else isnt


Can you tell me thy?




gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Add arc at polyline vertex
« Reply #13 on: December 29, 2012, 12:35:07 PM »
Hi,

I can't understand what point you're looking for, neither reading nor trying you code.
Could you attach a drawing showing some examples ?
Speaking English as a French Frog

krkec

  • Guest
Re: Add arc at polyline vertex
« Reply #14 on: January 02, 2013, 01:52:38 PM »
 I solved that problem. Thanks for help