Jump to content

DXF data extraction -- Find circle center of circle segment that is part of a polyline


Recommended Posts

Posted

I draw polylines that have circle segments for smoothing inside corners and such.

 

I want to extract the polyline data from the DXF.  I can find the polyline in the DXF and extract the start and end points of the various "VERTEX" items.  The circle segments have an identifier " 42 " that clues me in that the current segment is a circle segment.  But I am only finding the start point and end point for the circle segment.

 

How can I find the center point for each circle segment listed in the polyline data?

 

Attached are a simple polyline and CSV I extracted from the DXF.

CircleSegPolyLine.CSV CircleSegment-PolyLine.dxf

Posted

The entity definition - for example, Polyline, tries to be as efficient as it can be - uses the least dotted pair identifiers as possible... and so a smaller file size, stuff like that.

 

That means for polylines, code '42' identifies the bulge of a segment, 0 being flat (no curve) and is a result of the arcs centre point, radius and angle.

 

Afra Lisp gives a better description than I can here: https://www.afralisp.net/archive/lisp/Bulges1.htm

Lee Mac gives some LISPs here also: https://lee-mac.com/bulgeconversion.html

Posted

Hi

Try this

(defun dameCentroRadio
	 (pt1 pt2 asoc42 / dst alfa radio h angPerpn centro)
    (setq dst	   (distance pt1 pt2)
	  alfa	   (* 4 (atan asoc42))	; Ángulo del arco
	  radio	   (/ dst (* 2 (sin (/ alfa 2)))) ; Radio del arco
	  h	   (sqrt (- (* radio radio) (* (/ dst 2) (/ dst 2))))
					; Distancia del centro al punto medio				
	  angPerpn (+ (angle pt1 pt2)
		      (* (/ pi 2)
			 (if (> asoc42 0)
			   1
			   -1
			 )
		      )
		   )			; Ángulo perpendicular				
	  centro
		   (list
		     (+ (/ (+ (car pt1) (car pt2)) 2) (* h (cos angPerpn)))
		     (+ (/ (+ (cadr pt1) (cadr pt2)) 2) (* h (sin angPerpn)))
		   )
    )
    (list centro radio)	
) 

 

Posted (edited)
2 hours ago, GLAVCVS said:

Hi

Try this

(defun dameCentroRadio
	 (pt1 pt2 asoc42 / dst alfa radio h angPerpn centro)
    (setq dst	   (distance pt1 pt2)
	  alfa	   (* 4 (atan asoc42))	; Ángulo del arco
	  radio	   (/ dst (* 2 (sin (/ alfa 2)))) ; Radio del arco
	  h	   (sqrt (- (* radio radio) (* (/ dst 2) (/ dst 2))))
					; Distancia del centro al punto medio				
	  angPerpn (+ (angle pt1 pt2)
		      (* (/ pi 2)
			 (if (> asoc42 0)
			   1
			   -1
			 )
		      )
		   )			; Ángulo perpendicular				
	  centro
		   (list
		     (+ (/ (+ (car pt1) (car pt2)) 2) (* h (cos angPerpn)))
		     (+ (/ (+ (cadr pt1) (cadr pt2)) 2) (* h (sin angPerpn)))
		   )
    )
    (list centro radio)	
) 

 

This function will return a list with the center and radius.
Once you have both parameters, you can get all the points you want along the arc using:
 

(polar centro [sequence of possible angles between pt1 and pt2] radius)

 

Edited by GLAVCVS
Posted

Of course:
-pt1 is the start point of the arc
-pt2 is the end point of the arc
-asoc42 is the value returned by (cdr (assoc 42 ...))' on that segment

 

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...