Author Topic: splines with second degree curve data degrade?  (Read 9040 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: splines with second degree curve data degrade?
« Reply #15 on: December 17, 2011, 12:19:25 PM »
Here, I've made conversion of an ellipse to spline by our conclusions... Perhaps now try to draw tangent and see what happens...

Code: [Select]
(defun c:el2spl ( / CE CH DXF11 DXF40 EL ELSPL PTST SP1 SP1CV SP1EN SP1ST SP2 SP2CV SP2EN SP2ST SP3 SP3CV SP3EN SP3ST SP4 SP4CV SP4EN SP4ST SPSS SS )
  (setq ss (ssget "_:E:S:L" '((0 . "ELLIPSE"))))
  (setq el (ssname ss 0))
  (setq ce (cdr (assoc 10 (entget el))))
  (setq dxf11 (cdr (assoc 11 (entget el))))
  (setq dxf40 (cdr (assoc 40 (entget el))))
  (setq ptst (mapcar '+ ce dxf11))
  (setq sp1st ptst)
  (setq sp1en (polar ce (+ (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp1cv (polar sp1st (+ (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp1 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (210 0.0 0.0 1.0) (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 sp1st) (cons 41 1.0) (cons 10 sp1cv) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 sp1en) (cons 41 1.0)) )))
  (setq sp2st sp1en)
  (setq sp2en (polar ce (angle ptst ce) (distance ptst ce)))
  (setq sp2cv (polar sp2en (+ (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp2 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (210 0.0 0.0 1.0) (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 sp2st) (cons 41 1.0) (cons 10 sp2cv) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 sp2en) (cons 41 1.0)) )))
  (setq sp3st sp2en)
  (setq sp3en (polar ce (- (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp3cv (polar sp3st (- (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp3 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (210 0.0 0.0 1.0) (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 sp3st) (cons 41 1.0) (cons 10 sp3cv) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 sp3en) (cons 41 1.0)) )))
  (setq sp4st sp3en)
  (setq sp4en sp1st)
  (setq sp4cv (polar sp4en (- (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp4 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (210 0.0 0.0 1.0) (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 sp4st) (cons 41 1.0) (cons 10 sp4cv) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 sp4en) (cons 41 1.0)) )))
  (setq spss (ssadd))
  (ssadd sp1 spss)
  (ssadd sp2 spss)
  (ssadd sp3 spss)
  (ssadd sp4 spss)
  (vl-cmdf "_.splinedit" sp1 "j" spss "" "")
  (setq elspl (entlast))
  (initget 1 "Yes No")
  (setq ch (getkword "\nErase original ellipse and leave spline (Yes/No) : "))
  (if (eq ch "Yes") (entdel el))
(princ)
)

Regards, M.R.
:)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: splines with second degree curve data degrade?
« Reply #16 on: December 17, 2011, 12:39:55 PM »
No success with tan trick, but you can now convert elliptic spline to pline with splinedit and set precision up to 99...

M.R. (I don't know though why now trick with tan doesn't work - with 1 quarter of ellipse it worked)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: splines with second degree curve data degrade?
« Reply #17 on: December 17, 2011, 12:55:26 PM »
Here now the trick with tan works... Only thing is that now ellipse is converted into 4 quarters splines...

Code: [Select]
(defun c:el2spl ( / CE CH DXF11 DXF40 EL ELSPL PTST SP1 SP1CV SP1EN SP1ST SP2 SP2CV SP2EN SP2ST SP3 SP3CV SP3EN SP3ST SP4 SP4CV SP4EN SP4ST SS )
  (setq ss (ssget "_:E:S:L" '((0 . "ELLIPSE"))))
  (setq el (ssname ss 0))
  (setq ce (cdr (assoc 10 (entget el))))
  (setq dxf11 (cdr (assoc 11 (entget el))))
  (setq dxf40 (cdr (assoc 40 (entget el))))
  (setq ptst (mapcar '+ ce dxf11))
  (setq sp1st ptst)
  (setq sp1en (polar ce (+ (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp1cv (polar sp1st (+ (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp1 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (210 0.0 0.0 1.0) (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 sp1st) (cons 41 1.0) (cons 10 sp1cv) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 sp1en) (cons 41 1.0)) )))
  (setq sp2st sp1en)
  (setq sp2en (polar ce (angle ptst ce) (distance ptst ce)))
  (setq sp2cv (polar sp2en (+ (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp2 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (210 0.0 0.0 1.0) (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 sp2st) (cons 41 1.0) (cons 10 sp2cv) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 sp2en) (cons 41 1.0)) )))
  (setq sp3st sp2en)
  (setq sp3en (polar ce (- (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp3cv (polar sp3st (- (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp3 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (210 0.0 0.0 1.0) (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 sp3st) (cons 41 1.0) (cons 10 sp3cv) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 sp3en) (cons 41 1.0)) )))
  (setq sp4st sp3en)
  (setq sp4en sp1st)
  (setq sp4cv (polar sp4en (- (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  (setq sp4 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (210 0.0 0.0 1.0) (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 sp4st) (cons 41 1.0) (cons 10 sp4cv) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 sp4en) (cons 41 1.0)) )))
  (initget 1 "Yes No")
  (setq ch (getkword "\nErase original ellipse and leave spline (Yes/No) : "))
  (if (eq ch "Yes") (entdel el))
(princ)
)

[EDIT : Added another code]

Code - Auto/Visual Lisp: [Select]
  1. (defun c:el2spls ( / ce ch dxf11 dxf40 el elspl i ptst sp1 sp1cv sp1en sp1st sp2 sp2cv sp2en sp2st sp3 sp3cv sp3en sp3st sp4 sp4cv sp4en sp4st spss ss stpt enpt )
  2.   (setq ss (ssget "_:L" '((0 . "ELLIPSE"))))
  3.   (repeat (setq i (sslength ss))
  4.     (setq el (ssname ss (setq i (1- i))))
  5.     (command "_.ucs" "e" el)
  6.     (setq ce (cdr (assoc 10 (entget el))))
  7.     (setq dxf11 (cdr (assoc 11 (entget el))))
  8.     (setq dxf40 (cdr (assoc 40 (entget el))))
  9.     (setq ptst (mapcar '+ ce dxf11))
  10.     (setq ptst (trans ptst 0 1))
  11.     (setq ce (trans ce 0 1))
  12.     (setq sp1st ptst)
  13.     (setq sp1en (polar ce (+ (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  14.     (setq sp1cv (polar sp1st (+ (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  15.     (setq sp1 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 (trans sp1st 1 0)) (cons 41 1.0) (cons 10 (trans sp1cv 1 0)) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 (trans sp1en 1 0)) (cons 41 1.0) (assoc 210 (entget el))) )))
  16.     (setq sp2st sp1en)
  17.     (setq sp2en (polar ce (angle ptst ce) (distance ptst ce)))
  18.     (setq sp2cv (polar sp2en (+ (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  19.     (setq sp2 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 (trans sp2st 1 0)) (cons 41 1.0) (cons 10 (trans sp2cv 1 0)) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 (trans sp2en 1 0)) (cons 41 1.0) (assoc 210 (entget el))) )))
  20.     (setq sp3st sp2en)
  21.     (setq sp3en (polar ce (- (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  22.     (setq sp3cv (polar sp3st (- (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  23.     (setq sp3 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 (trans sp3st 1 0)) (cons 41 1.0) (cons 10 (trans sp3cv 1 0)) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 (trans sp3en 1 0)) (cons 41 1.0) (assoc 210 (entget el))) )))
  24.     (setq sp4st sp3en)
  25.     (setq sp4en sp1st)
  26.     (setq sp4cv (polar sp4en (- (angle ptst ce) (/ PI 2.0)) (* dxf40 (distance ptst ce))))
  27.     (setq sp4 (entmakex (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline") (70 . 12) (71 . 2) (72 . 6) (73 . 3) (74 . 0) (42 . 1.0e-010) (43 . 1.0e-010) (40 . 0.0) (40 . 0.0) (40 . 0.0) (40 . 1.0) (40 . 1.0) (40 . 1.0)) (list (cons 10 (trans sp4st 1 0)) (cons 41 1.0) (cons 10 (trans sp4cv 1 0)) (cons 41 (/ (sqrt 2.0) 2.0)) (cons 10 (trans sp4en 1 0)) (cons 41 1.0) (assoc 210 (entget el))) )))
  28.     (setq spss (ssadd))
  29.     (setq stpt (vlax-curve-getstartpoint el))
  30.     (setq enpt (vlax-curve-getendpoint el))
  31.     (command "_.ucs" "w")
  32.     (cond
  33.       ((vlax-curve-getparamatpoint sp1 stpt)
  34.        (ssadd sp1 spss)
  35.        (ssadd sp2 spss)
  36.        (ssadd sp3 spss)
  37.        (ssadd sp4 spss)
  38.        (vl-cmdf "_.splinedit" sp1 "j" spss "" "")
  39.        (setq elspl (entlast))
  40.       )
  41.       ((vlax-curve-getparamatpoint sp2 stpt)
  42.        (ssadd sp2 spss)
  43.        (ssadd sp3 spss)
  44.        (ssadd sp4 spss)
  45.        (ssadd sp1 spss)
  46.        (vl-cmdf "_.splinedit" sp2 "j" spss "" "")
  47.        (setq elspl (entlast))
  48.       )
  49.       ((vlax-curve-getparamatpoint sp3 stpt)
  50.        (ssadd sp3 spss)
  51.        (ssadd sp4 spss)
  52.        (ssadd sp1 spss)
  53.        (ssadd sp2 spss)
  54.        (vl-cmdf "_.splinedit" sp3 "j" spss "" "")
  55.        (setq elspl (entlast))
  56.       )
  57.       ((vlax-curve-getparamatpoint sp4 stpt)
  58.        (ssadd sp4 spss)
  59.        (ssadd sp1 spss)
  60.        (ssadd sp2 spss)
  61.        (ssadd sp3 spss)
  62.        (vl-cmdf "_.splinedit" sp4 "j" spss "" "")
  63.        (setq elspl (entlast))
  64.       )
  65.     )
  66.     (command "_.break" elspl stpt enpt)
  67.     (entupd (cdr (assoc -1 (entmod (subst (assoc 8 (entget el)) (assoc 8 (entget elspl)) (entget elspl))))))
  68.     (if (assoc 62 (entget el)) (entupd (cdr (assoc -1 (entmod (append (entget elspl) (list (assoc 62 (entget el)))))))))
  69.     (if (assoc 420 (entget el)) (entupd (cdr (assoc -1 (entmod (append (entget elspl) (list (assoc 420 (entget el)))))))))
  70.     (entdel el)
  71.     (command "_.ucs" "p")
  72.     (command "_.ucs" "p")
  73.   )
  74.   (princ)
  75. )
  76.  

M.R.
« Last Edit: March 11, 2015, 02:33:36 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

SEANT

  • Bull Frog
  • Posts: 345
Re: splines with second degree curve data degrade?
« Reply #18 on: December 17, 2011, 04:45:12 PM »
Interesting work.  As programmers, investigating how AutoCAD responds in all situations justifies this type of effort. 

I am curious, though:  Is there a design/documentation need for the extreme entities contained in the previous files?
Sean Tessier
AutoCAD 2016 Mechanical