### Author Topic: ellipse to arc  (Read 804 times)

0 Members and 1 Guest are viewing this topic.

#### jack91066

• Mosquito
• Posts: 11
##### ellipse to arc
« on: March 17, 2017, 05:37:21 pm »
Hi everyone,

Please anyone help me try to convert ellipse to arc, i attach my cad file. in my cad file ellipse major and minor radius is not equal,
i use lee-mac lisp tyr to convert my cad file but not success.
if anybody have idea ,please share with me how to convert ellipse to arc

#### gile

• Water Moccasin
• Posts: 2089
• Marseille, France
##### Re: ellipse to arc
« Reply #1 on: March 17, 2017, 06:10:21 pm »
Hi

Not sure it's what you're looking for, but here's a quite old but not so bad one (I quickly translated the prompts to English).

Code - Auto/Visual Lisp: [Select]
`;;; ARCEDIT (gile) 25/11/2005;;; Convertit un cercle ou une ellipse en arc ou modifie le départ et la fin;;; d'un arc d'après les angles spécifiés, l'option "Fermer" permet la conversion d'un;;; arc de cercle en cercle ou d'un arc elliptique en ellipse fermée. (defun c:arcedit (/ ucszdir getang ang->param set1 ent lst ang1	ang2 opt		  echo)   ;; ucszdir Retourne la direction d'extrusion du SCU courant (vecteur)  (defun ucszdir ()    (trans '(0 0 1) 1 0 T)  )   ;; Saisie des angles de départ et de fin de l'arc (option "Fermer")  (defun getang	()    (if	(or (= (cdr (assoc 0 lst)) "CIRCLE")	    (and (= (cdr (assoc 0 lst)) "ELLIPSE")		 (= (cdr (assoc 41 lst)) 0.0)		 (= (cdr (assoc 42 lst)) (* 2 pi))	    )	)      (progn (setq opt "") (initget 1))      (progn (setq opt " ou [Close] <f>:") (initget "Close"))    )    (if	(numberp (setq ang1			(getangle (trans (cdr (assoc 10 lst)) ent 1)				  (strcat "\nSpecify the arc start angle"					  opt					  ": "				  )			)		 )	)      (progn	(initget 1)	(setq ang2	       (getangle (trans (cdr (assoc 10 lst)) ent 1)			 "\nSpecify the arc end angle: "	       )	)	(foreach ang '(ang1 ang2)	  (set ang	       (+ (eval ang)		  (angle '(0 0) (trans (getvar "UCSXDIR") 0 (ucszdir)))		  (getvar "ANGBASE")	       )	  )	)      )    )  )   ;; Convertit l'angle saisi en "paramètre" de l'ellipse (code dxf 41 et 42)  (defun ang->param (ang)    (setq      ang (- ang	     (angle '(0 0) (trans (cdr (assoc 11 lst)) 0 (ucszdir)))	  )    )    (atan (sin ang) (* (cos ang) (cdr (assoc 40 lst))))  )   ;; Fonction principale  (if (and (= 1 (getvar "PICKFIRST"))	   (setq set1 (ssget "_i" '((0 . "ARC,CIRCLE,ELLIPSE"))))	   (eq 1 (sslength set1))      )    (progn      (setq ent	(ssname set1 0)	    lst	(entget ent)      )      (sssetfirst nil nil)    )    (progn      (sssetfirst nil nil)      (while	(not	  (and	    (setq ent		   (car	(entsel			  "\nSelect an arc, a circle or an ellipse: "			)		   )	    )	    (setq lst (entget ent))	    (member (cdr (assoc 0 lst)) '("ARC" "CIRCLE" "ELLIPSE"))	  )	)      )    )  )  (if (equal (ucszdir) (cdr (assoc 210 lst)) 1e-9)    (progn      (getang)      (cond	((= (cdr (assoc 0 lst)) "ARC")	 (if (numberp ang1)	   (setq lst (subst (cons 50 ang1)			    (assoc 50 lst)			    (subst (cons 51 ang2) (assoc 51 lst) lst)		     )	   )	   (setq	     lst (cons '(0 . "CIRCLE")		       (vl-remove-if			 '(lambda (x)			    (member (car x) '(-1 0 330 5 100 50 51))			  )			 lst		       )		 )	   )	 )	)	((= (cdr (assoc 0 lst)) "CIRCLE")	 (setq lst		(cons		  '(0 . "ARC")		  (cons		    (cons 50 ang1)		    (cons		      (cons 51 ang2)		      (vl-remove-if			'(lambda (x) (member (car x) '(-1 0 330 5 100)))			lst		      )		    )		  )		)	 )	)	((= (cdr (assoc 0 lst)) "ELLIPSE")	 (if (numberp ang1)	   (foreach ang	'(ang1 ang2)	     (set ang (ang->param (eval ang)))	   )	   (setq ang1 0.0		 ang2 (* 2 pi)	   )	 )	 (setq lst (subst (cons 41 ang1)			  (assoc 41 lst)			  (subst (cons 42 ang2) (assoc 42 lst) lst)		   )	 )	)      )      (setq echo (getvar "CMDECHO"))      (setvar "CMDECHO" 0)      (command "_undo" "_begin")      (entmake lst)      (entdel ent)      (command "_undo" "_end")      (setvar "CMDECHO" echo)    )    (princ      "\nError: the current UCS and the object OCS are not parallel."    )  )  (princ))`
Speaking English as a French Frog

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #2 on: March 17, 2017, 06:20:36 pm »
(defun c:e2a (/ acaddoc acadms acadobj center endangle obj radius ss ssn startangle)
(vl-load-com)
(if
(setq ss (ssget '((0 . "ellipse"))))
(progn
(setq acadobj (vlax-get-acad-object))
(setq acaddoc (vla-get-activeDocument acadobj))
(setq acadms (vla-get-modelspace acaddoc))
(setq ssn (ssname ss 0))
(setq obj (vlax-ename->vla-object ssn))
(if
obj ;(equal (vla-get-RadiusRatio obj) 1 0.0001)
(progn
(setq radius (vla-get-MajorRadius obj))
(setq StartAngle (vla-get-StartAngle OBJ))
(setq EndAngle (vla-get-EndAngle obj))
(setq Center (vlax-get obj 'center))
(entdel ssn)
(vla-addarc acadms (vlax-3d-point Center) radius StartAngle EndAngle)
) ; progn
(alert "> Ellipse objects failed to be converted")
)   ; if
)     ; progn
)       ; if
(princ)
)       ; defun

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #3 on: March 17, 2017, 06:23:03 pm »
i use this code but is not working because my major and minor radius in not equal have any another code if major and minor radius not equal it working.

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #4 on: March 17, 2017, 06:24:39 pm »
check my attach cad file

#### gile

• Water Moccasin
• Posts: 2089
• Marseille, France
##### Re: ellipse to arc
« Reply #5 on: March 17, 2017, 06:27:58 pm »
This one converts ellipse or elliptical arc into a polyline with circular arc segments.
Try EL2PL command.

Code - Auto/Visual Lisp: [Select]
`;; EllipseToPolyline;; Returns a polyline (vla-object) which is an approximation of the ellipse (or elliptical arc);;;; Argument : an ellipse (vla-object) (defun EllipseToPolyline (el	/     cl    norm  cen	elv   pt0   pt1	  pt2	pt3   pt4   ac0			  ac4	a04   a02   a24	  bsc0	bsc2  bsc3  bsc4  plst	blst  spt   spa			  fspa	srat  ept   epa	  fepa	erat  n			 )  (vl-load-com)  (setq	cl   (= (ang<2pi (vla-get-StartAngle el))		(ang<2pi (vla-get-EndAngle el)))	norm (vlax-get el 'Normal)	cen  (trans (vlax-get el 'Center) 0 norm)	elv  (caddr cen)	cen  (3dTo2dPt cen)	pt0  (mapcar '+ (trans (vlax-get el 'MajorAxis) 0 norm) cen)	ac0  (angle cen pt0)	pt4  (mapcar '+ cen (trans (vlax-get el 'MinorAxis) 0 norm))	pt2  (3dTo2dPt (trans (vlax-curve-getPointAtparam el (/ pi 4.)) 0 norm))	ac4  (angle cen pt4)	a04  (angle pt0 pt4)	a02  (angle pt0 pt2)	a24  (angle pt2 pt4)	bsc0 (/ (ang<2pi (- a02 ac4)) 2.)	bsc2 (/ (ang<2pi (- a04 a02)) 2.)	bsc3 (/ (ang<2pi (- a24 a04)) 2.)	bsc4 (/ (ang<2pi (- (+ ac0 pi) a24)) 2.)	pt1  (inters pt0		     (polar pt0 (+ ac0 (/ pi 2.) bsc0) 1.)		     pt2		     (polar pt2 (+ a02 bsc2) 1.)		     nil	     )	pt3  (inters pt2		     (polar pt2 (+ a04 bsc3) 1.)		     pt4		     (polar pt4 (+ a24 bsc4) 1.)		     nil	     )	plst (list pt4 pt3 pt2 pt1 pt0)	blst (mapcar '(lambda (b) (tan (/ b 2.)))		     (list bsc4 bsc3 bsc2 bsc0)	     )  )  (foreach b blst    (setq blst (cons b blst))  )  (foreach b blst    (setq blst (cons b blst))  )  (foreach p (cdr plst)    (setq ang  (angle cen p)	  plst (cons		 (polar cen (+ ang (* 2 (- ac4 ang))) (distance cen p))		 plst	       )    )  )  (foreach p (cdr plst)    (setq ang  (angle cen p)	  plst (cons		 (polar cen (+ ang (* 2 (- ac0 ang))) (distance cen p))		 plst	       )    )  )  (setq	pl	 (vlax-invoke	   (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))	   'AddLightWeightPolyline	   (apply 'append		  (setq	plst			 (reverse (if cl				    (cdr plst)				    plst				  )			 )		  )	   )	 )  )  (vlax-put pl 'Normal norm)  (vla-put-Elevation pl elv)  (mapcar '(lambda (i v) (vla-SetBulge pl i v))	  '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)	  blst  )  (if cl    (vla-put-Closed pl :vlax-true)    (progn      (setq spt	 (vlax-curve-getClosestPointTo pl (vlax-get el 'Startpoint))	    spa	 (vlax-curve-getParamAtPoint pl spt)	    fspa (fix spa)	    ept	 (vlax-curve-getClosestPointTo pl (vlax-get el 'Endpoint))	    epa	 (vlax-curve-getParamAtPoint pl ept)	    fepa (fix epa)	    n	 0      )      (cond	((equal spt (trans pt0 norm 0) 1e-9)	 (if (= epa fepa)	   (setq plst (sublist plst 0 (1+ fepa))		 blst (sublist blst 0 (1+ fepa))	   )	   (setq erat (/ (- (vlax-curve-getDistAtParam pl epa)			    (vlax-curve-getDistAtParam pl fepa)			 )			 (- (vlax-curve-getDistAtParam pl (rem (1+ fepa) 17))			    (vlax-curve-getDistAtParam pl fepa)			 )		      )		 plst (append (sublist plst 0 (1+ fepa))			      (list (3dTo2dPt (trans ept 0 norm)))		      )		 blst (append (sublist blst 0 (1+ fepa))			      (list (k*bulge (nth fepa blst) erat))		      )	   )	 )	)	((equal ept (trans pt0 norm 0) 1e-9)	 (if (= spa fspa)	   (setq plst (sublist plst fspa nil)		 blst (sublist blst fspa nil)	   )	   (setq srat (/ (- (vlax-curve-getDistAtParam pl (rem (1+ fspa) 17))			    (vlax-curve-getDistAtParam pl spa)			 )			 (- (vlax-curve-getDistAtParam pl (rem (1+ fspa) 17))			    (vlax-curve-getDistAtParam pl fspa)			 )		      )		 plst (cons (3dTo2dPt (trans spt 0 norm))			    (sublist plst (1+ fspa) nil)		      )		 blst (cons (k*bulge (nth fspa blst) srat)			    (sublist blst (1+ fspa) nil)		      )	   )	 )	)	(T	 (setq srat (/ (- (vlax-curve-getDistAtParam pl (rem (1+ fspa) 17))			  (vlax-curve-getDistAtParam pl spa)		       )		       (- (vlax-curve-getDistAtParam pl (rem (1+ fspa) 17))			  (vlax-curve-getDistAtParam pl fspa)		       )		    )	       erat (/ (- (vlax-curve-getDistAtParam pl epa)			  (vlax-curve-getDistAtParam pl fepa)		       )		       (- (vlax-curve-getDistAtParam pl (rem (1+ fepa) 17))			  (vlax-curve-getDistAtParam pl fepa)		       )		    )	 )	 (if (< epa spa)	   (setq plst (append			(if (= spa fspa)			  (sublist plst fspa nil)			  (cons	(3dTo2dPt (trans spt 0 norm))				(sublist plst (1+ fspa) nil)			  )			)			(cdr (sublist plst 0 (1+ fepa)))			(if (/= epa fepa)			  (list (3dTo2dPt (trans ept 0 norm)))			)		      )		 blst (append			(if (= spa fspa)			  (sublist blst fspa nil)			  (cons			    (k*bulge (nth fspa blst) srat)			    (sublist blst (1+ fspa) nil)			  )			)			(sublist blst 0 fepa)			(if (= epa fepa)			  (list (nth fepa blst))			  (list (k*bulge (nth fepa blst) erat))			)		      )	   )	   (setq plst (append			(if (= spa fspa)			  (sublist plst fspa (1+ (- fepa fspa)))			  (cons	(3dTo2dPt (trans spt 0 norm))				(sublist plst (1+ fspa) (- fepa fspa))			  )			)			(list (3dTo2dPt (trans ept 0 norm)))		      )		 blst (append			(if (= spa fspa)			  (sublist blst fspa (- fepa fspa))			  (cons			    (k*bulge (nth fspa blst) srat)			    (sublist blst (1+ fspa) (- fepa fspa))			  )			)			(if (= epa fepa)			  (list (nth fepa blst))			  (list (k*bulge (nth fepa blst) erat))			)		      )	   )	 )	)      )      (vlax-put pl 'Coordinates (apply 'append plst))      (foreach b blst	(vla-SetBulge pl n b)	(setq n (1+ n))      )    )  )  pl) ;; Ang<2pi;; Returns the angle expression betweem 0 and 2*pi(defun ang<2pi (ang)  (if (and (<= 0 ang) (< ang (* 2 pi)))    ang    (ang<2pi (rem (+ ang (* 2 pi)) (* 2 pi)))  )) ;; 3dTo2dPt;; Returns the 2d point (x y) of a 3d point (x y z)(defun 3dTo2dPt (pt) (list (car pt) (cadr pt))) ;; Tan;; Returns the angle tangent(defun tan (a) (/ (sin a) (cos a))) ;; SUBLIST ;; Returns a sub list;;;; Arguments;; lst : a list;; start : start index (first item = 0);; leng : the sub list length (number of items) or nil(defun sublist (lst start leng / n r)  (if (or (not leng) (< (- (length lst) start) leng))    (setq leng (- (length lst) start))  )  (setq n (+ start leng))  (while (< start n)    (setq r (cons (nth (setq n (1- n)) lst) r))  )) ;; K*BULGE;; Returns the proportinal bulge to the référence bulge;; Arguments :;; b : the bulge;; k : the proportion ratio (between angles or arcs length)(defun k*bulge (b k / a)  (setq a (atan b))  (/ (sin (* k a)) (cos (* k a)))) ;; EL2PL;; Converts ellipses and elliptcal arcs into polylines (defun c:el2pl (/ *error* fra acdoc ss)  (vl-load-com)  (defun *error* (msg)    (if	(and (/= msg "Fonction annulée")	     (/= msg "Function cancelled")	)      (princ (strcat (if (= "FRA" (getvar 'locale))		       "\nErreur: "		       "\Error: "		     )		     msg	     )      )    )    (vla-endUndoMark acdoc)    (princ)  )  (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))  (if (ssget '((0 . "ELLIPSE")))    (progn      (vla-StartUndoMark acdoc)      (vlax-for	e (setq ss (vla-get-ActiveSelectionSet acdoc))	(EllipseToPolyline e)	(vla-delete e)      )      (vla-delete ss)      (vla-EndUndoMark acdoc)    )  )  (princ)) ;; PELL;; Draws an ellipse or an elliptical arc approximation (polyline) on the fly(defun c:pell (/ *error* ec pe old ent)  (vl-load-com)  (defun *error* (msg)    (if	(and msg	     (/= msg "Fonction annulée")	     (/= msg "Function cancelled")	)      (princ (strcat (if (= "FRA" (getvar 'locale))		       "\nErreur: "		       "\Error: "		     )		     msg	     )      )    )    (setvar 'cmdecho ec)    (setvar 'pellipse pe)    (princ)  )  (setq	ec  (getvar 'cmdecho)	pe  (getvar 'pellipse)	old (entlast)  )  (setvar 'cmdecho 1)  (setvar 'pellipse 0)  (command "_.ellipse")  (while (/= 0 (getvar 'cmdactive))    (command pause)  )  (if (not (eq old (setq ent (entlast))))    (progn      (EllipseToPolyline (vlax-ename->vla-object ent))      (entdel ent)    )  )  (*error* nil))`
Speaking English as a French Frog

#### gile

• Water Moccasin
• Posts: 2089
• Marseille, France
##### Re: ellipse to arc
« Reply #6 on: March 17, 2017, 06:41:18 pm »
Warning, elliptical arc start point and end point might be slightly different after the conversion.
Keep in mind you can only approximate an ellispe with circular arcs.
The ellipse approximation in the upper code is the same as the on done by AutoCAD when PELLIPSE sysvar is set to 1.
« Last Edit: March 17, 2017, 06:47:14 pm by gile »
Speaking English as a French Frog

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #7 on: March 17, 2017, 07:04:52 pm »
sir ,
i need only arc object if because my cnc machine in take only arc boject.
i try to send some photo.

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #8 on: March 17, 2017, 07:06:34 pm »
i send another photo compare both photo

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #9 on: March 17, 2017, 07:16:09 pm »
;;-------------------=={ Ellipse to Arc }==-------------------;;
;;                                                            ;;
;;  Converts circular Ellipses & Elliptical Arcs (i.e. for    ;;
;;  which the Ellipse Axis Ratio = 1.0) to Circles & Arcs,    ;;
;;  whilst retaining all original properties. Works with      ;;
;;  Ellipses & Elliptical Arcs constructed in any UCS.        ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:e2a ( / a b c e i m p q r s u v z )
(if (setq s (ssget "_:L" '((0 . "ELLIPSE") (40 . 1.0))))
(repeat (setq i (sslength s))
(setq e (entget (ssname s (setq i (1- i))))
z (cdr (assoc 210 e))
c (trans (cdr (assoc 10 e)) 0 z)
p (trans (cdr (assoc 11 e)) 0 z)
a (distance '(0.0 0.0) p)
b (* a (cdr (assoc 40 e)))
r (angle '(0.0 0.0) p)
u (cdr (assoc 41 e))
v (cdr (assoc 42 e))
m (list (list (cos r) (- (sin r))) (list (sin r) (cos r)))
p (mapcar '+ c (mxv m (list (* a (cos u)) (* b (sin u)))))
q (mapcar '+ c (mxv m (list (* a (cos v)) (* b (sin v)))))
)
(if
(if (equal p q 1e-8)
(entmake
(cons '(0 . "CIRCLE")
(append (LM:defaultprops e)
(list
(cons  010 c)
(cons  040 a)
(assoc 210 e)
)
)
)
)
(entmake
(cons '(0 . "ARC")
(append (LM:defaultprops e)
(list
(cons  010 c)
(cons  040 a)
(cons  050 (angle c p))
(cons  051 (angle c q))
(assoc 210 e)
)
)
)
)
)
(entdel (cdr (assoc -1 e)))
)
)
)
(princ)
)

;; Default Properties  -  Lee Mac
;; Returns a list of DXF properties for the supplied DXF data,
;; substituting default values for absent DXF groups

(defun LM:defaultprops ( elist )
(mapcar
(function
(lambda ( pair )
(cond ((assoc (car pair) elist)) ( pair ))
)
)
'(
(008 . "0")
(006 . "BYLAYER")
(039 . 0.0)
(062 . 256)
(048 . 1.0)
(370 . -1)
)
)
)

;; Matrix x Vector  -  Vladimir Nesterovsky
;; Args: m - nxn matrix, v - vector in R^n

(defun mxv ( m v )
(mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
)

(princ)

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #10 on: March 17, 2017, 07:19:57 pm »
i use that coding but if major and minor radius is same that coding is work.
if i change major and minor radius  then that coding is not working.
if any coding have please share ........

#### roy_043

• Swamp Rat
• Posts: 1492
• BricsCAD 16
##### Re: ellipse to arc
« Reply #11 on: March 17, 2017, 08:00:26 pm »
Why not use Gile's EllipseToPolyline function and then explode the resulting polyline?

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #12 on: March 17, 2017, 08:14:46 pm »
sir
roy_043

my cnc machine is only take arc object,
if you have any idea about it..

#### gile

• Water Moccasin
• Posts: 2089
• Marseille, France
##### Re: ellipse to arc
« Reply #13 on: March 18, 2017, 03:36:52 am »
Hi,

As said roy_043, you can simply explode the polylines generated by EL2PL and so get only arcs.

a video
Speaking English as a French Frog

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #14 on: March 18, 2017, 03:52:47 pm »
thanks Gile's and roy_04 sir..............

#### jack91066

• Mosquito
• Posts: 11
##### Re: ellipse to arc
« Reply #15 on: March 20, 2017, 04:53:25 pm »
sir Gile's

when i complete all is process that arc object divide to much object

As said roy_043, when simply explode the polylines generated by EL2PL and so get  arcs to much. i don't need to much arc object.
if have any idea

#### gile

• Water Moccasin
• Posts: 2089
• Marseille, France
##### Re: ellipse to arc
« Reply #16 on: March 20, 2017, 06:06:30 pm »
Except when the major axis equals the minor axis (i.e. the ellipse is a circle), you cannot approximate an ellipse with a circle, so you can't approximate an elliptical arc with a single circular arc.
It is a geometric impossibility.
« Last Edit: March 20, 2017, 06:12:13 pm by gile »
Speaking English as a French Frog

#### Lee Mac

• Seagull
• Posts: 11831
• AutoCAD 2015 Windows 7 London, England
##### Re: ellipse to arc
« Reply #17 on: March 20, 2017, 06:36:34 pm »
Except when the major axis equals the minor axis (i.e. the ellipse is a circle), you cannot approximate an ellipse with a circle, so you can't approximate an elliptical arc with a single circular arc.
It is a geometric impossibility.

This ^^