Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ellipse > user specified tangent arcs [approximation]

14 REPLIES 14
Reply
Message 1 of 15
Anonymous
1344 Views, 14 Replies

Ellipse > user specified tangent arcs [approximation]

Hello all,
Does anyone have a routine for this? I have to doe this a lot at my job,
and I can't think of an easy way to a accomplish this with autolisp.
In my case I almost always need to replace an ellipse that is tangent to 2
lines.
How I do it now is first try a 3point circle. Tan-Tan-MidPointEllipse if
the circle is very close to ellipse then I just fillet the 2 lines.
Else, I break the ellipse into segments, creating 3point crircles from both
sides then a circle tan-LeftCircle-tanRightCircle-MidPointEllipse then trim
all of these up.

This is very time consuming, I am hoping there might be a routine out there
already that can do this.

Thanks
Rodney
14 REPLIES 14
Message 2 of 15
Anonymous
in reply to: Anonymous

Rodney Estep wrote:
> ...
> How I do it now is first try a 3point circle. Tan-Tan-MidPointEllipse if
> the circle is very close to ellipse then I just fillet the 2 lines.
> Else, I break the ellipse into segments, creating 3point crircles from both
> sides then a circle tan-LeftCircle-tanRightCircle-MidPointEllipse then trim
> all of these up.
> ...
>
It's hard to tell from your description just what you need to do. Send
screen shots?
Message 3 of 15
Anonymous
in reply to: Anonymous

Bill this should give you an idea. Most CNC programming softwares do not
handle an ellipse with interpolation, they break it up into polygonal
segments based on a fit tolerance, and the results can be faceted which is
not desireable. So I redraw these shapes using tangent arcs and smoothness
of the cut profile is much better. In this drawing the part is being cut on
an wire edm machine with UV tilt, the part actually has a .75 radius but it
is tilted in the stock which makes the drive curve at the top and bottom of
the part elliptical. This comes up pretty often, I am just trying to turn a
5~15 minute job into a 1~2 click operation.

Thanks
Rodney



"Bill Gilliss" wrote in message
news:6257258@discussion.autodesk.com...
Rodney Estep wrote:
> ...
> How I do it now is first try a 3point circle. Tan-Tan-MidPointEllipse if
> the circle is very close to ellipse then I just fillet the 2 lines.
> Else, I break the ellipse into segments, creating 3point crircles from
> both
> sides then a circle tan-LeftCircle-tanRightCircle-MidPointEllipse then
> trim
> all of these up.
> ...
>
It's hard to tell from your description just what you need to do. Send
screen shots?
Message 4 of 15
Anonymous
in reply to: Anonymous

Easiest method, np programming required:

If you set the PELLIPSE system variable to 1, AutoCAD draws an "ellipse"
or an "elliptical arc" composed of tangential arc segments instead of a
true ellipse.

These tangential arcs are extremely close to the original elliptical
shape, as you can tell if you use the same axis endpoints to create a
true ellipse and a polyline ellipse on top of each other.

Explode the polyline into individual arcs if this is what the CNC
process needs.


-Bill
Message 5 of 15
Anonymous
in reply to: Anonymous

Easiest method, no programming required:

Set the system variable PELLIPSE to 1, which will make the ellipse
command create a tangential-arc polyline instead of a true ellipse or
elliptical arc. Explode the polyline if the CNC process wants simple arcs.

These arc segments approximate the true ellipse to a very high degree of
accuracy, as you can tell by using the same axis endpoints to create a
true ellipse and a polyline one on top of each other.

-Bill
Message 6 of 15
_gile
in reply to: Anonymous

Hi,

AFAIK, while PELLIPSE is set to 1 you can't draw arcs.

Here's an old LISP I wrote to convert ellipses (or elliptical arcs) into polylines. It uses the PELLIPSE = 1 behavior and breaks the polyline according to the source ellipse start and end angles.

Two commands are defined:
- EL2PL to convert a selection set of ellipses
- ELP to draw an ellipse (or elliptical arc) which is automatically converted in polyline.

{code};; ELLIPSE->POLYLINE
;; Converts an ellipse (or an elliptical arc) into a polyline
;;
;; Arguement
;; ent : une ellipse (ename)

(defun ellipse->polyline (ent / os ec pe elst cen ext pa1 pa2 grd prd
ang pt1 pt2 mat)
(setq ec (getvar "cmdecho")
pe (getvar "pellipse")
elst (entget ent)
cen (trans (cdr (assoc 10 elst)) 0 1)
ext (mapcar '+ cen (cdr (assoc 11 elst)))
pa1 (cdr (assoc 41 elst))
pa2 (cdr (assoc 42 elst))
grd (distance cen ext)
prd (* grd (cdr (assoc 40 elst)))
ang (- (angle cen ext)
(angle '(0 0 0) (getvar "ucsxdir"))
)
)
(entdel ent)
(setvar "cmdecho" 0)
(setvar "pellipse" 1)
(command "_.ellipse" "_c" "_non" cen "_non" (polar cen ang grd) prd)
(if (or (/= pa1 0.0) (/= pa2 (* 2 pi)))
(progn
(setq ent (entlast)
pt1 (list (* grd (cos pa1)) (* prd (sin pa1)))
pt2 (list (* grd (cos pa2)) (* prd (sin pa2)))
mat (list (list (cos ang) (- (sin ang)) 0)
(list (sin ang) (cos ang) 0)
'(0 0 1)
)
pt1 (mapcar '+ cen (mxv mat pt1))
pt2 (mapcar '+ cen (mxv mat pt2))
)
(cond
((equal ext pt2 1e-9)
(command "_.break" ent "_non" pt2 "_non" pt1)
)
((equal ext pt1 1e-9)
(command "_.break" ent "_non" pt2 "_non" pt2)
(entdel (entlast))
)
((< (atof (angtos pa2)) (atof (angtos pa1)))
(command "_.break" ent "_non" pt1 "_non" pt1)
(setq ent (entnext ent))
(command "_.break" ent "_non" pt2 "_non" pt1)
(command "_.pedit" (entnext ent) "_j" (entlast) "" "")
)
(T
(command "_.break" ent "_non" ext "_non" pt1)
(command "_.break" ent "_non" pt2 "_non" ext)
)
)
)
)
(command "_.convert" "_p" "_s" (entlast) "")
(setvar "cmdecho" ec)
(setvar "pellipse" pe)
)

;;===================================================;;

;; ELP
;; Creates a polyline figuring an ellipse (or an elliptical arc)

(defun c:elp (/ *error* ec pe old ent)

(defun *error* (msg)
(if (= msg "Function cancelled")
(princ)
(princ (strcat "\nError: " 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))))
(ellipse->polyline ent)
)
(setvar "cmdecho" ec)
(setvar "pellipse" pe)
(princ)
)

;;===================================================;;

;; EL2PL
;; Converts a selection set of ellipses (or an elliptical arcs) into polylines
(defun c:el2pl (/ ss n)
(if (setq n 0
ss (ssget '((0 . "ELLIPSE")))
)
(repeat (sslength ss)
(ellipse->polyline (ssname ss n))
(setq n (1+ n))
)
)
(princ (strcat "\n\t"
(itoa n)
" ellipse(s) converted into polylines"
)
)
(princ)
){code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 15
Anonymous
in reply to: Anonymous

You are right that elliptical arcs cannot be created when PELLIPSE is
set to 1. I was assuming that the OP would draw a full polyline ellipse,
and then trim it to the horizontal and vertical lines.

_gile wrote:
> Hi,
>
> AFAIK, while PELLIPSE is set to 1 you can't draw arcs.
Message 8 of 15
Anonymous
in reply to: Anonymous

Gile,
This routine works good but I am wondering if mxv is a subroutine that
would trim the pline on the starting and ending point of the ellipse.
This subroutine is missing. I can figure out how to do that from here if
that is not the case.

Thanks
Rodney


"_gile" wrote in message news:6257289@discussion.autodesk.com...
Hi,

AFAIK, while PELLIPSE is set to 1 you can't draw arcs.

Here's an old LISP I wrote to convert ellipses (or elliptical arcs) into
polylines. It uses the PELLIPSE = 1 behavior and breaks the polyline
according to the source ellipse start and end angles.

Two commands are defined:
- EL2PL to convert a selection set of ellipses
- ELP to draw an ellipse (or elliptical arc) which is automatically
converted in polyline.

{code};; ELLIPSE->POLYLINE
;; Converts an ellipse (or an elliptical arc) into a polyline
;;
;; Arguement
;; ent : une ellipse (ename)

(defun ellipse->polyline (ent / os ec pe elst cen ext pa1 pa2 grd prd
ang pt1 pt2 mat)
(setq ec (getvar "cmdecho")
pe (getvar "pellipse")
elst (entget ent)
cen (trans (cdr (assoc 10 elst)) 0 1)
ext (mapcar '+ cen (cdr (assoc 11 elst)))
pa1 (cdr (assoc 41 elst))
pa2 (cdr (assoc 42 elst))
grd (distance cen ext)
prd (* grd (cdr (assoc 40 elst)))
ang (- (angle cen ext)
(angle '(0 0 0) (getvar "ucsxdir"))
)
)
(entdel ent)
(setvar "cmdecho" 0)
(setvar "pellipse" 1)
(command "_.ellipse" "_c" "_non" cen "_non" (polar cen ang grd) prd)
(if (or (/= pa1 0.0) (/= pa2 (* 2 pi)))
(progn
(setq ent (entlast)
pt1 (list (* grd (cos pa1)) (* prd (sin pa1)))
pt2 (list (* grd (cos pa2)) (* prd (sin pa2)))
mat (list (list (cos ang) (- (sin ang)) 0)
(list (sin ang) (cos ang) 0)
'(0 0 1)
)
pt1 (mapcar '+ cen (mxv mat pt1))
pt2 (mapcar '+ cen (mxv mat pt2))
)
(cond
((equal ext pt2 1e-9)
(command "_.break" ent "_non" pt2 "_non" pt1)
)
((equal ext pt1 1e-9)
(command "_.break" ent "_non" pt2 "_non" pt2)
(entdel (entlast))
)
((< (atof (angtos pa2)) (atof (angtos pa1)))
(command "_.break" ent "_non" pt1 "_non" pt1)
(setq ent (entnext ent))
(command "_.break" ent "_non" pt2 "_non" pt1)
(command "_.pedit" (entnext ent) "_j" (entlast) "" "")
)
(T
(command "_.break" ent "_non" ext "_non" pt1)
(command "_.break" ent "_non" pt2 "_non" ext)
)
)
)
)
(command "_.convert" "_p" "_s" (entlast) "")
(setvar "cmdecho" ec)
(setvar "pellipse" pe)
)

;;===================================================;;

;; ELP
;; Creates a polyline figuring an ellipse (or an elliptical arc)

(defun c:elp (/ *error* ec pe old ent)

(defun *error* (msg)
(if (= msg "Function cancelled")
(princ)
(princ (strcat "\nError: " 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))))
(ellipse->polyline ent)
)
(setvar "cmdecho" ec)
(setvar "pellipse" pe)
(princ)
)

;;===================================================;;

;; EL2PL
;; Converts a selection set of ellipses (or an elliptical arcs) into
polylines
(defun c:el2pl (/ ss n)
(if (setq n 0
ss (ssget '((0 . "ELLIPSE")))
)
(repeat (sslength ss)
(ellipse->polyline (ssname ss n))
(setq n (1+ n))
)
)
(princ (strcat "\n\t"
(itoa n)
" ellipse(s) converted into polylines"
)
)
(princ)
){code}
Message 9 of 15
_gile
in reply to: Anonymous

Sorry, I forgot joining mxv routine.

Here's a new (better) version which works whatever the ellipses construction plane and current UCS.

{code};; ELLIPSE->POLYLINE
;; ELLIPSE->POLYLINE
;; Converts an ellipse (or an elliptical arc) into a polyline
;;
;; Arguement
;; ent : une ellipse (ename)

(defun ellipse->polyline (ent / elst ucs os ec pe cen ext pa1 pa2 grd prd ang
pt1 pt2 mat line ed)
(setq elst (entget ent))
(or
(equal (trans '(0 0 1) 1 0 T) (cdr (assoc 210 elst)) 1e-9)
(and
(setq ucs T)
(command "_.ucs" "_zaxis" '(0 0 0) (trans (cdr (assoc 210 elst)) ent 1 T))
)
)
(setq ec (getvar "cmdecho")
pe (getvar "pellipse")
elst (entget ent)
cen (cdr (assoc 10 elst))
elv (caddr (trans cen 0 (cdr (assoc 210 elst))))
ext (trans (mapcar '+ cen (cdr (assoc 11 elst))) 0 1)
cen (trans cen 0 1)
pa1 (cdr (assoc 41 elst))
pa2 (cdr (assoc 42 elst))
grd (distance cen ext)
prd (* grd (cdr (assoc 40 elst)))
ang (angle cen ext)
)
(entdel ent)
(setvar "cmdecho" 0)
(setvar "pellipse" 1)
(command "_.ellipse" "_c" "_non" cen "_non" (polar cen ang grd) prd)
(if (or (/= pa1 0.0) (/= pa2 (* 2 pi)))
(progn
(setq ent (entlast)
pt1 (list (* grd (cos pa1)) (* prd (sin pa1)))
pt2 (list (* grd (cos pa2)) (* prd (sin pa2)))
mat (list (list (cos ang) (- (sin ang)) 0)
(list (sin ang) (cos ang) 0)
'(0 0 1)
)
pt1 (mapcar '+ cen (mxv mat pt1))
pt2 (mapcar '+ cen (mxv mat pt2))
)
(command "_.line" "_non" pt1 "_non" pt2 "")
(setq line (entlast))
(cond
((equal ext pt2 1e-9)
(command "_.break" ent "_non" pt1 "_non" pt1)
(entdel (entnext line))
)
((equal ext pt1 1e-9)
(command "_.break" ent "_non" pt2 "_non" pt2)
(entdel (entlast))
)
((< (atof (angtos pa2)) (atof (angtos pa1)))
(setq ed (getvar "EDGEMODE"))
(setvar "EDGEMODE" 1)
(command "_.trim" line "" (polar cen (+ ang pi) grd) "")
(setvar "EDGEMODE" ed)
(command "_.pedit" (entlast) "_j" (entnext line) "" "")
)
(T
(setq ed (getvar "EDGEMODE"))
(setvar "EDGEMODE" 1)
(command "_.trim" line "" ext "")
(setvar "EDGEMODE" ed)
)
)
(entdel line)
)
)
(command "_.convert" "_p" "_s" (entlast) "")
(and ucs (command "_.ucs" "_previous"))
(setvar "cmdecho" ec)
(setvar "pellipse" pe)
)

;;===================================================;;

;; MXV
;; Applies a transformation matrix to a vector -Vladimir Nesterovsky-
;;
;; Arguments : a matrix and a vector

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

;;===================================================;;

;; ELP
;; Creates a polyline figuring an ellipse (or an elliptical arc)

(defun c:elp (/ *error* ec pe old ent)

(defun *error* (msg)
(if (= msg "Function cancelled")
(princ)
(princ (strcat "\nError: " 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))))
(ellipse->polyline ent)
)
(setvar "cmdecho" ec)
(setvar "pellipse" pe)
(princ)
)

;;===================================================;;

;; EL2PL
;; Converts a selection set of ellipses (or an elliptical arcs) into
polylines
(defun c:el2pl (/ ss n)
(setq n 0)
(if (setq ss (ssget '((0 . "ELLIPSE"))))
(progn
(command "_.undo" "_begin")
(repeat (sslength ss)
(ellipse->polyline (ssname ss n))
(setq n (1+ n))
)
(command "_.undo" "_end")
)
)
(princ (strcat "\n\t" (itoa n) " ellipse(s) converted into polyline(s)"
)
)
(princ)
){code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 10 of 15
Anonymous
in reply to: Anonymous

1. Set PELLIPSE to 1.

2. Draw the ellipse with the Center option, finding the center with
Object Tracking and Osnap enabled, and specifying the endpoints of the
lines as the axis endpoints.

3. Trim.

That's it. The last step shows the polyline arc segments.
Message 11 of 15
_gile
in reply to: Anonymous

Hi Bill,

With ELP, you draw an elliptical arc with the same options as ELLIPSE while PELLIPSE is set to 1 but the created object is a polyline.
EL2PL allows to convert all selected ellses and elliptical arcs into polylines.


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 12 of 15
Anonymous
in reply to: Anonymous

Gile,
Thanks again, it work great. Btw, what app are you using for the screen
capture video. I have used Snagit but the file size gets massive. I could
use this for making tutorials for one of my programs.

Thanks
Rodney


"_gile" wrote in message news:6257373@discussion.autodesk.com...
Hi Bill,

With ELP, you draw an elliptical arc with the same options as ELLIPSE while
PELLIPSE is set to 1 but the created object is a polyline.
EL2PL allows to convert all selected ellses and elliptical arcs into
polylines.
Message 13 of 15
_gile
in reply to: Anonymous

I use Camtasia Studio (same editor as Snagit).


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 14 of 15
Anonymous
in reply to: Anonymous

Gile -

Don't misunderstand me: we do indeed bow before you. I was just trying
to see how close I could get to your solution without any coding.

Here's a new problem (to me, anyhow): construct a ellipse tangent to the
four sides of a rhombus, either with equal sides or two pairs of equal
sides. I got to it by wondering how to generate an elliptical fillet for
two non-orthogonal lines, maintaining as in Rodney's example the
existing endpoints. This ended up being a subset of the rhombus puzzle.

Can it be done by construction, or must we resort to iteration?

-Bill
Message 15 of 15
Kent1Cooper
in reply to: Anonymous

This may not be "worth it" to you, depending on the degree of precision you need, but here's another approach:

Draw a "true" Ellipse rather than a Polyline-arc approximation, and use the WobblyPline.lsp routine [WPL command] attached to the last post on this thread:

http://discussion.autodesk.com/forums/message.jspa?messageID=6044735&tstart=0

to turn it into a Polyline that can *much more precisely* follow the true elliptical path. WPL lets you choose the degree of wobbliness, and that can be *zero*, in which case the vertices of the Polyline it makes will lie exactly *on* the path of the thing converted.

The attached shows the difference, with indication of the scale of things, and how far a Polyline-arc-approximation Ellipse can stray from the true elliptical path, so you can judge whether it's enough to adversely affect precision.

The not-Wobbly Polyline [magenta color] is made of line segments, but many short ones [it's selected, with grips showing at the vertices], so the segmentation can be as little as you want, or as much as you can tolerate. This one was done dividing the original elliptical arc into 100 segments, but WPL lets you choose how many -- make it 1000 if you want! It also lets you choose whether to keep or delete the source path, and has other interesting features.

Another time-saving advantage: you *don't* need to first make the elliptical arc, or the full polyline-approximation ellipse and then trim it, and then apply WPL to it. You can build the elliptical arc [or any other kind of path you choose] *within* WPL, which lets you choose whether to make the path inside the routine, or select an EXisting path.

--
Kent Cooper


Rodney Estep wrote...
....
Most CNC programming softwares do not handle an ellipse with interpolation, they break it up into polygonal segments based on a fit tolerance, and the results can be faceted which is not desireable. ....
Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report