Author Topic: how to entmake ellipse arc?  (Read 4124 times)

0 Members and 1 Guest are viewing this topic.

taner

  • Guest
how to entmake ellipse arc?
« on: August 05, 2007, 09:01:05 PM »
if a ellipse is exist,and two point on the ellipse.how to entmake the ellipse arc?tks!

Adesu

  • Guest
Re: how to entmake ellipse arc?
« Reply #1 on: August 05, 2007, 10:19:55 PM »
Hi taner,
This code is to create as you want, but sorry use entmake become not suitable as you request, I thinks it should you use by arc command function.
Code: [Select]
(defun c:test (/ clay ctr eang ep etyp om oom rad sang sp ss sse)
  (setq om (getvar "osmode"))
  (setvar "osmode" 512)
  (if
    (setq ss (car (entsel "\nSelect an ellipse exist")))
    (progn
      (setq sse (entget ss))
      (setq etyp (cdr (assoc 0 sse)))
      (if
(= etyp "ELLIPSE")
(progn
  (setq ctr (cdr (assoc 10 sse)))
  (setq sp (osnap (getpoint "\nPick point for start: ") "_nea"))
  (setq ep (osnap (getpoint "\nPick point for end: ") "_nea"))
  (setq clay (cdr (assoc 8 sse)))
  (setq rad (distance ctr sp))
  (setq sang (angle ctr sp))
  (setq eang (angle ctr ep))
  (command "_erase" ss "")
  (entmake
    (list
      '(0 . "ARC")
      (cons 8 clay)
      '(100 . "AcDbCircle")
      (cons 10 ctr)
      (cons 40 (/ rad 2.0))
      '(100 . "AcDbArc")
      (cons 50 sang)
      (cons 51 eang)))
  )  ; progn
(alert "\nInvalid selected object,it's not ellipse")
)    ; if
      )      ; progn
    (alert "\nInvalid selected object,please try again")
    )        ; if
  (setvar "osmode" om)
  (princ)
  )          ; defun

if a ellipse is exist,and two point on the ellipse.how to entmake the ellipse arc?tks!

taner

  • Guest
Re: how to entmake ellipse arc?
« Reply #2 on: August 05, 2007, 11:33:40 PM »
Tkanks for your reply. I am sorry iI do not express what i want clearly because of my poor english. I  means that there is a ellipse and two points on it. I want to use entmake method to make a part of a ellipse.The new entity is also ellipse,but not whole ellipse.the new entity is a part of the ellipse.

Adesu

  • Guest
Re: how to entmake ellipse arc?
« Reply #3 on: August 05, 2007, 11:50:45 PM »
Why not use with break function.

Tkanks for your reply. I am sorry iI do not express what i want clearly because of my poor english. I  means that there is a ellipse and two points on it. I want to use entmake method to make a part of a ellipse.The new entity is also ellipse,but not whole ellipse.the new entity is a part of the ellipse.

taner

  • Guest
Re: how to entmake ellipse arc?
« Reply #4 on: August 06, 2007, 12:56:07 AM »
ellipse can not be broken at one point.

Adesu

  • Guest
Re: how to entmake ellipse arc?
« Reply #5 on: August 06, 2007, 02:01:12 AM »
Hi taner,
how about this code
Code: [Select]
(defun c:test (/ el etyp om pt1 pt2 ss sse)
  (setq om (getvar "osmode"))
  (setvar "osmode" 512)
  (if
    (setq ss (car (entsel "\nSelect bottom part an ellipse")))
    (progn
      (setq sse (entget ss))
      (setq etyp (cdr (assoc 0 sse)))
      (if
(= etyp "ELLIPSE")
(progn
  (setq pt1 (osnap (getpoint "\nPick first point for break: ") "_nea"))
  (setq pt2 (osnap (getpoint "\nPick next point for break: ") "_nea"))  
  (command "_line" pt1 pt2 "")
  (setq el (entlast))
  (command "_trim" ss el "" ss "")
  (command "_erase" el "") 
  )  ; progn
(alert "\nInvalid selected object,it's not ellipse")
)    ; if
      )      ; progn
    (alert "\nInvalid selected object,please try again")
    )        ; if
  (setvar "osmode" om)
  (princ)
  )          ; defun


ellipse can not be broken at one point.

taner

  • Guest
Re: how to entmake ellipse arc?
« Reply #6 on: August 06, 2007, 02:33:27 AM »
It is not what i want too.  I want to break all entitys at their intersections, so I use entmake to rebulid circles composed of arcs,and ellipse composed of section ellipse.

Adesu

  • Guest
Re: how to entmake ellipse arc?
« Reply #7 on: August 06, 2007, 02:39:19 AM »
 :angel:

It is not what i want too.  I want to break all entitys at their intersections, so I use entmake to rebulid circles composed of arcs,and ellipse composed of section ellipse.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: how to entmake ellipse arc?
« Reply #8 on: August 06, 2007, 12:28:28 PM »
Hi,

something like this ?

Code: [Select]
(defun ellipse2arc (ell pt1 pt2 / nor cen ang1 ang2 par1 par2)
  (setq elst (entget ell)
nor (cdr (assoc 210 elst))
cen  (trans (cdr (assoc 10 elst)) 0 nor)
ang1 (- (angle cen (trans pt1 0 nor))
(angle '(0 0) (trans (cdr (assoc 11 elst)) 0 nor))
     )
ang2 (- (angle cen (trans pt2 0 nor))
(angle '(0 0) (trans (cdr (assoc 11 elst)) 0 nor))
     )
par1 (atan (sin ang1) (* (cos ang1) (cdr (assoc 40 elst))))
par2 (atan (sin ang2) (* (cos ang2) (cdr (assoc 40 elst))))
  )
  (entmod
    (subst (cons 41 par1)
   (assoc 41 elst)
   (subst (cons 42 par2) (assoc 42 elst) elst)
    )
  )
)
« Last Edit: August 06, 2007, 01:19:20 PM by gile »
Speaking English as a French Frog

Fatty

  • Guest
Re: how to entmake ellipse arc?
« Reply #9 on: August 06, 2007, 01:20:25 PM »
Hi gile
Nice work, thanks :)
Regards,

~'J'~

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: how to entmake ellipse arc?
« Reply #10 on: August 06, 2007, 04:08:43 PM »
Thanks, Fatty.

taner,

perhaps I mis-understand, but if you want to 'cut' the ellipse at the two points, making two jointive arcs, replace:

Code: [Select]
(entmod
    (subst (cons 41 par1)
   (assoc 41 elst)
   (subst (cons 42 par2) (assoc 42 elst) elst)
    )
  )

by:

Code: [Select]
(entmake
    (subst (cons 41 par1)
   (assoc 41 elst)
   (subst (cons 42 par2) (assoc 42 elst) elst)
    )
  )
  (entmake
    (subst (cons 41 par2)
   (assoc 41 elst)
   (subst (cons 42 par1) (assoc 42 elst) elst)
    )
  )
  (entdel ell)

in the code I posted above.
Speaking English as a French Frog

taner

  • Guest
Re: how to entmake ellipse arc?
« Reply #11 on: August 07, 2007, 04:09:41 AM »
hi,dear gile ,your are rigth. but the problem is how to get par1 and par2.
 Fools give me the code as below, it works well.
  • (defun test (pt cen axis ratio / ang param)
      (setq ang (- (angle cen pt) (angle '(0. 0. 0.) axis)))
      (cond
        ((= (cos ang) 0.0)         ; 防止分母cos为零出错
          (if (> (sin ang) 0.0)
     (setq param (* 0.5 pi))
     (setq param (* 1.5 pi))
          )
        )
        ((= (sin ang) 0.0)
          (if (> (cos ang) 0.0)
     (setq param 0.0)
     (setq param pi)
          )
        )
        (t
          (setq param (atan (/ (sin ang) (* (cos ang) ratio))))
          (if (< (cos ang) 0.0)
     (setq param (+ pi param))
          )
        )
      )
      param
    )

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: how to entmake ellipse arc?
« Reply #12 on: August 07, 2007, 08:22:34 AM »
Hi taner,

Look at the atan function in vlisp help, il allows even one or two arguments (numbers) :

(atan (/ a b)) is the same as (atan a b) but using the second way, exempts to check if b is 0.

(atan 1 0) returns 1.5708

Look at the code I posted above (ellipse2arc), to calculate the param, just do :

(setq par1 (atan (sin ang1) (* (cos ang1) (cdr (assoc 40 elst))))
   par2 (atan (sin ang2) (* (cos ang2) (cdr (assoc 40 elst))))
)

without checking the value of angles.
Speaking English as a French Frog

taner

  • Guest
Re: how to entmake ellipse arc?
« Reply #13 on: August 07, 2007, 10:04:11 AM »
Thanks, it's perfect!