Jump to content

Finding specific points of an arc within a polyline


nlandry83

Recommended Posts

I'm needing to find the coordinates of a specific point of an arc within a polyline using VBA. I'm not sure exactly what you would call this point, but basically it would be the vertex of two lines that if you used the fillet command would create the arc shown in the polyline. I have attached a picture to show what I am looking for.

points.JPG

Link to comment
Share on other sites

IP Intersection point, no code rather method lisp vba .net the all have a method of working out what segment of the pline you have picked so in simple terms you would make two new lines and work out the intersection point, then erase two lines, you may be able also to use ray lines hence dont actually exist. The old lisp INTERS command supports 4 point intersection (inters p1 p2 p3 p4) solution v's vl instersectwith which needs two objects.

 

So search for VBA pline segments etc. If some one does not answer sooner.

Link to comment
Share on other sites

Found some time this is in lisp but pretty easy to convert to VBA

 

In the code no check if you have picked a radius or a straight. The line command is so you can see something for the result.

 

Its not perfect need a bit more time has problem where the radius is the last section but close.

 

; Intersection point of plines where radius exists
; By Alan H June 2019

(defun PSN (plsel / )
  (1+
          (fix
            (vlax-curve-getParamAtPoint (car plsel)
              (osnap (cadr plsel) "_nea")
            )
          )
        )
) 


(defun ah:IPP (  /  pt1 pt2 pt3 pt4 pt5 seg1 seg2 plent)
(setq plent (entsel "Select Polyline Radius"))
(setq seg1 (- (psn plent) 1))
(setq seg2 (+ seg1 2))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(if (> seg2 (length co-ord))(setq seg2 1))
(setq pt1 (nth (1- seg1) co-ord))
(setq pt2 (nth  seg1 co-ord))
(setq pt3 (nth (1- seg2) co-ord))
(setq pt4 (nth  seg2 co-ord))
(if (= pt4 nil)(setq pt4 (nth 0 co-ord)))
(setq pt5 (inters pt1 pt2 pt3 pt4 nil))
(command "line" pt5 (list 0 0) "")
(princ)
)

(ah:IPP)
Edited by BIGAL
Link to comment
Share on other sites

Thank you BIGAL. It seemed to work for point B but not for the other two points. I was thinking of maybe going in a different direction but not sure how it could be done. Is there a way to pull the intersection points of all the lines within the polyline? So, basically ignoring the arcs all together. I would still need to keep the polyline intact though.

Link to comment
Share on other sites

Here's a simple process that has you manually pick the arc segment start, end, and center to find the intersection point.  Use it with osnap set to end and cen.  YOu could adapt the process to work on all arc segments of a polyline.

 

(defun c:AV (/ p1 p2 p3 p4 p ang osm)
  (setq	p1   (getpoint "\nSelect arc beginning.")
	p2   (getpoint p1 "\nSelect arc end.")
	pctr (getpoint p2 "\nSelect arc center.")
	ang  (angle pctr p1)
	p3   (polar p1 (+ ang (/ pi 2.)) 10)
	ang  (angle pctr p2)
	p4   (polar p2 (+ ang (/ pi 2.)) 10)
	p    (inters p1 p3 p2 p4 nil)
  )
  (setq osm (getvar "osmode"))
  (command "_line" pctr p "")
  (setvar "osmode" osm)
  (princ)
)

 

Link to comment
Share on other sites

Thanks Irm. It works great! I'm having some trouble adapting this to VBA though. Mainly with the 'angle' and 'polar' portions of the equation. Do you know of a way to adapt that to VBA?

Link to comment
Share on other sites

I don't have access to AutoCAD/VBA but wrote the following using Excel/VBA which you could adapt to AutoCAD/VBA.

 

I used some vector algebra (i.e., cross product) rather than tri to determine a perpendicular line to the radial line for the arc as it avoids potential problems with vertical lines (slope = 0). Note that an arc that subtends 180° will cause an error as the tangent lines to the arc's end point are parallel and thus do not intersect.

Sub ArcVertex()
Range("B2:b2").Select
p1x = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
p1y = ActiveCell.Value
ActiveCell.Offset(1, -1).Select
p2x = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
p2y = ActiveCell.Value
ActiveCell.Offset(1, -1).Select
pcenx = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
pceny = ActiveCell.Value

Call cross(pcenx - p1x, pceny - p1y, 0, 0, 0, 1, p3x, p3y, p3z)
p3x = p3x + p1x
p3y = p3y + p1y
Call cross(pcenx - p2x, pceny - p2y, 0, 0, 0, 1, p4x, p4y, p4z)
p4x = p4x + p2x
p4y = p4y + p2y

Range("B6:B6").Select
ActiveCell.Value = p3x
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = p3y
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = p4x
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = p4y

pintx = ((p3x * p1y - p1x * p3y) * (p4x - p2x) - (p4x * p2y - p2x * p4y) * (p3x - p1x)) / _
         ((p3x - p1x) * (p4y - p2y) - (p4x - p2x) * (p3y - p1y))

pinty = ((p3x * p1y - p1x * p3y) * (p4y - p2y) - (p4x * p2y - p2x * p4y) * (p3y - p1y)) / _
         ((p3x - p1x) * (p4y - p2y) - (p4x - p2x) * (p3y - p1y))

ActiveCell.Offset(1, -1).Select
ActiveCell.Value = pintx
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = pinty

End Sub

Sub cross(ax, ay, az, bx, by, bz, cx, cy, cz)
cx = ay * bz - az * by
cy = az * bx - ax * bz
cz = ax * by - ay * bx
End Sub

 

image.png.3825681f2520d1b25eab63b0704f2442.png

 

 

arc_vertex.zip

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...