Get coordinates every 1 meter from the polyline

Get coordinates every 1 meter from the polyline

seabrahenrique
Advocate Advocate
2,562 Views
2 Replies
Message 1 of 3

Get coordinates every 1 meter from the polyline

seabrahenrique
Advocate
Advocate

Hi Guys,

 

I'm working on code that I need the coordinates of a polyline.

 

I usually use:

Dim PL As AcadLWPolyline, CoordsPL As Variant

CoordsPL = PL.Coordinates

 

However, I would need more coordinates than this command gives me.

So I thought of some way to draw some polylines on my polyline, but I was unsuccessful.


Any ideas to help? Thanks in advance 🙂

0 Likes
Accepted solutions (2)
2,563 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

With AutoCAD COM API (AutoCAD VBA), unfortunately, you need to do some math, starting from the start point of the polyline (Light weight polyline, I assume, to make things simpler/easier), and go through next vertex one at a segment between 2 vertices:

 

For each 1 unit long (meter, in your case, or whatever for that matter), you can calculate the coordinate of the point 1.0 meter far from the start vertex by

x=Cos(1.0) and Y=Sin(1.0); at the next vertex, if it is not right a the end of 1.0 meter (most likely), you substract the remainder length from 1.0 meter before you calculate the next 1.0 meter end's coordinate from the next vertex; keep going on until you done the whole length of the polyline; If the polyline has arc segment, you need to get the arc's radius to calculate the coordinate on the arc (you know the arc length (1.0 meter; or less because of previous vertex) and radius, you can calculate the arc angle, then calculate the coordinates. Yes, it is quite tedious process, but all are very basic high school math that anyone who programs AutoCAD should be capable of doing.

 

However, if you do AutoCAD .NET programming, the .NET API saves you from doing it by yourself. It have something like:

 

Dim point As Poin3d = Curve[Line, Polyline, Arc...].GetPointAtDist(distance As Double)

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

seabrahenrique
Advocate
Advocate
Accepted solution

Hello @norman.yuan 

 

I would like to thank you for the answer and say that the proposed reasoning helped me a lot in the solution.

 

The only problem with using it in 100% of the cases was that in my case the polylines were 3Dpoly representing lanes on a highway and that many times they started straight, but ended up in curves which I couldn't access the angles.

 

Anyway, I found a solution from the development of a function in VBA that I believe is similar to the one you mentioned that exists in .NET...

 

I'll put it here to help other developers in the future:

 

Function FA_FindPointatDist (PL3D As Acad3DPolyline, ByVal DistBase As Double, FindPoint As Variant) 'Returns the exact distance point above the Polyline

Dim Coords () As Double
Dim Sum As Double, Dist As Double, i As Integer
Dim PTi (0 To 2) As Double, PTf (0 To 2) As Double, LastPT (0 To 2) As Double, Ang As Double
Sum = 0: i = 0: Coords = PL3D.Coordinates

Do While (Sum <= DistBase)

Dist = Sqr ((Coords (i + 3) - Coords (i + 0)) ^ 2 + (Coords (i + 4) - Coords (i + 1)) ^ 2 + (Coords (i + 5) - Coords ( i + 2)) ^ 2)
PTi (0) = Coords (i + 0): PTi (1) = Coords (i + 1): PTf (0) = Coords (i + 3): PTf (1) = Coords (i + 4)
Ang = ThisDrawing.Utility.AngleFromXAxis (PTf, PTi)
Sum = Sum + Dist
i = i + 3
Loop

LastPT (0) = Coords (i)
LastPT (1) = Coords (i + 1)
LastPT (2) = Coords (i + 2)

FindPoint = ThisDrawing.Utility.PolarPoint (LastPT, Ang, Sum - DistBase)

End Function

 


From the formula it is possible to find the coordinates of a polyline according to the distance informed by the user, I believe that the .NET function mentioned does exactly that, which solves the case.

 

Thank you again 🙂

0 Likes