Author Topic: - = { Challenge } = - 2D 3rd degree curve -> 2nd degree curve (cir,ell,par,hyp)  (Read 2739 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Given the fact that you can now reliably construct 3rd degree spline entity in UCS plane as 2D planar curve...
See this post :
http://www.theswamp.org/index.php?topic=48885.msg540487#msg540487

And the fact that we know basic ways to construct main 2nd degree curves (circle, ellipse, parabola, hyperbola)...
See attached *.DWG...

Raises new challenge : find the best way to convert 3rd degree planar spline entity to corresponding 2nd degree spline entity that describes in the best way (the best overlapping) mentioned main 2nd degree curves... Attached DWG shows how differ those types of curves... Lisp is acceptable, but if there is a better way avoiding coding please share your discovery with us all...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Here are my solutions for drawing parabolas and hyperbolas in 3D in active UCS... I think that conversion of constructed 3rd degree splines are too complex, so I figured I should post what's possible; for circles and ellipses one can simply use CIRCLE and ELLIPSE commands...

Code - Auto/Visual Lisp: [Select]
  1. (defun parabmake ( pt1 ptt pt2 aa / pttcv pt111 pt222 pt11 pt22 level expr ptpar )
  2.  
  3.   (defun ptpar ( pt1 ptt pt2 aa / pt12m dpt12m t12 t1122 p11 p22 pp12 pt11 pt22 )
  4.     (setq pt12m (mapcar '/ (mapcar '+ pt1 pt2) (list 2.0 2.0 2.0)))
  5.     (setq dpt12m (distance pt12m ptt))
  6.     (setq t12 (polar ptt aa dpt12m))
  7.     (setq t1122 (polar ptt aa (* dpt12m 4)))
  8.     (setq p11 (polar t12 (angle t12 pt1) (* 1.5 (distance t12 pt1))))
  9.     (setq p22 (polar t12 (angle t12 pt2) (* 1.5 (distance t12 pt2))))
  10.     (setq pp12 (polar ptt (- aa) (* dpt12m 4)))
  11.     (setq pt11 (inters pp12 (polar pp12 (angle pt2 pt1) 1.0) t1122 p11 nil))
  12.     (setq pt22 (inters pp12 (polar pp12 (angle pt1 pt2) 1.0) t1122 p22 nil))
  13.     (list pt11 ptt pt22)
  14.   )
  15.  
  16.   (initget 5)
  17.   (setq level (getint "\nInput level of parabola extension beyond picked point through witch parabola passes (0 <= level) : "))
  18.   (if (eq level 0)
  19.     (setq pt111 pt1 pt222 pt2)
  20.     (progn
  21.       (setq expr (list ptpar 'pt1 'ptt 'pt2 'aa))
  22.       (repeat (- level 1)
  23.         (setq pt11 (car (eval expr)))
  24.         (setq ptt (cadr (eval expr)))
  25.         (setq pt22 (caddr (eval expr)))
  26.         (setq pt1 pt11 pt2 pt22)
  27.       )
  28.       (setq pt111 (car (eval expr)))
  29.       (setq pt222 (caddr (eval expr)))
  30.     )
  31.   )
  32.   (setq pttcv (polar ptt aa (distance ptt (mapcar '/ (mapcar '+ pt111 pt222) (list 2.0 2.0 2.0)))))
  33.   (setq pt111 (trans pt111 1 0) pt222 (trans pt222 1 0) pttcv (trans pttcv 1 0))
  34.   (entmake (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline")) (list (cons 210 (trans '(0.0 0.0 1.0) 1 0 t))) '((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 pt111) (cons 41 1.0) (cons 10 pttcv) (cons 41 1.0) (cons 10 pt222) (cons 41 1.0)) ))
  35. )
  36.  
  37. (defun c:parabola ( / cmde osm ptt pt1 pt2 pt li axvec aa )
  38.  
  39.  
  40.   (setq osm (getvar 'osmode))
  41.   (setq cmde (getvar 'cmdecho))
  42.   (setvar 'cmdecho 0)
  43.   (setq ptt (getpoint "\nPick apex point of parabola : "))
  44.   (setq pt1 (getpoint "\nPick point through witch passes parabola and it is on one side of symetrical branch of parabola : "))
  45.   (setq pt (getpoint ptt "\nPick point that define axis between two branches of parabola - direction vector : "))
  46.   (setvar 'osmode 0)
  47.   (if (< (distance pt1 (polar ptt (angle ptt pt) (distance ptt pt1))) (* (sqrt 2.0) (distance ptt pt1)))
  48.     (setq pt (polar ptt (angle ptt pt) (distance ptt pt1)))
  49.     (setq pt (polar ptt (angle pt ptt) (distance ptt pt1)))
  50.   )
  51.   (setq li (entmakex (list '(0 . "LINE") (cons 10 (trans ptt 1 0)) (cons 11 (trans pt 1 0)))))
  52.   (setq pt (trans (vlax-curve-getclosestpointto li (trans pt1 1 0)) 0 1))
  53.   (entdel li)
  54.   (setq axvec (mapcar '- ptt pt))
  55.   (setq aa (angle '(0.0 0.0 0.0) axvec))
  56.   (setq pt2 (mapcar '+ pt (mapcar '- pt pt1)))
  57.   (parabmake pt1 ptt pt2 aa)
  58.   (setvar 'cmdecho cmde)
  59.   (setvar 'osmode osm)
  60.   (princ)
  61. )
  62.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:3p-parabola ( / cmde osm ptt pt1 pt2 pt ptcv )
  2.   (setq osm (getvar 'osmode))
  3.   (setq cmde (getvar 'cmdecho))
  4.   (setvar 'cmdecho 0)
  5.   (setq ptt (getpoint "\nPick apex point of parabola : "))
  6.   (setq pt1 (getpoint "\nPick point through witch passes parabola from one side of parabola branches : "))
  7.   (setq pt (getpoint ptt "\nPick point that define axis between two branches of parabola - point must be exact - oblique parabola : "))
  8.   (setvar 'osmode 0)
  9.   (setq pt2 (mapcar '+ pt (mapcar '- pt pt1)))
  10.   (setq ptcv (mapcar '+ ptt (mapcar '- ptt pt)))
  11.   (setq pt1 (trans pt1 1 0) pt2 (trans pt2 1 0) ptcv (trans ptcv 1 0))
  12.   (entmake (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline")) (list (cons 210 (trans '(0.0 0.0 1.0) 1 0 t))) '((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 pt1) (cons 41 1.0) (cons 10 ptcv) (cons 41 1.0) (cons 10 pt2) (cons 41 1.0)) ))
  13.   (setvar 'cmdecho cmde)
  14.   (setvar 'osmode osm)
  15.   (princ)
  16. )
  17.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:hyperbola ( / a al angl ar axis axvec b bb bt gr o pt pt1 pt11 pt22 ptax ptt pttcv ptx pty r1 r2 r3 r4 weightcv xpt ypt )
  2.  
  3.  
  4.   (setq pt1 (getpoint "\nPick point through witch passes hyperbola : "))
  5.   (setq o (getpoint "\nPick point of center of coordinate system of hyperbola : "))
  6.   (setq ptt (getpoint o "\nPick apex point of 2 branches of hyperbola, its main axis : "))
  7.   (setq a (distance o ptt))
  8.   (setq axvec (mapcar '- ptt o))
  9.   (setq ar ptt)
  10.   (setq al (polar o (angle axvec '(0.0 0.0 0.0)) a))
  11.   (vl-cmdf "_.xline" "b" o ar ar "")
  12.   (setq axis (entlast))
  13.   (setq ptx (distance (trans o 1 0) (setq pt (vlax-curve-getclosestpointto axis (trans pt1 1 0)))))
  14.   (setq pty (distance (trans pt 0 1) pt1))
  15.   (setq b (/ (* a pty) (sqrt (- (* ptx ptx) (* a a)))))
  16.   (setq bt (polar o (+ (angle '(0.0 0.0 0.0) axvec) (/ PI 2.0)) b))
  17.   (setq bb (polar o (- (angle '(0.0 0.0 0.0) axvec) (/ PI 2.0)) b))
  18.   (setq r1 (polar ar (+ (angle '(0.0 0.0 0.0) axvec) (/ PI 2.0)) b))
  19.   (setq r2 (polar al (+ (angle '(0.0 0.0 0.0) axvec) (/ PI 2.0)) b))
  20.   (setq r3 (polar al (- (angle '(0.0 0.0 0.0) axvec) (/ PI 2.0)) b))
  21.   (setq r4 (polar ar (- (angle '(0.0 0.0 0.0) axvec) (/ PI 2.0)) b))
  22.   (vl-cmdf "_.pline" r1 r2 r3 r4 "c")
  23.   (vl-cmdf "_.xline" "b" o bt bt "")
  24.   (vl-cmdf "_.xline" "b" o r1 r1 "")
  25.   (vl-cmdf "_.xline" "b" o r4 r4 "")
  26.   (prompt "\nPick point for extension of hyperbola - projection on main axis must be more distanced than border limits of apex point")
  27.   (while (eq 5 (car (setq gr (grread T 15 0))))
  28.       (redraw)
  29.       (grdraw (cadr gr)
  30.              (setq ptax (trans (vlax-curve-getClosestPointTo axis (trans (cadr gr) 1 0)) 0 1))
  31.              3
  32.              1
  33.       )
  34.   )
  35.   (setq xpt (distance o ptax))
  36.   (setq ypt (/ (* b (sqrt (- (* xpt xpt) (* a a)))) a))
  37.   (setq pt11 (polar ptax (+ (angle '(0.0 0.0 0.0) axvec) (/ PI 2.0)) ypt))
  38.   (setq pt22 (polar ptax (- (angle '(0.0 0.0 0.0) axvec) (/ PI 2.0)) ypt))
  39.   (setq weightcv (/ (- xpt a) (- a (/ (* a a) xpt))))
  40.   (if (< (distance ar ptax) (distance al ptax)) (setq ptt ar angl (angle axvec '(0.0 0.0 0.0))) (setq ptt al angl (angle '(0.0 0.0 0.0) axvec)))
  41.   (setq pttcv (polar ptt angl (- a (/ (* a a) xpt))))
  42.   (setq pt11 (trans pt11 1 0) pt22 (trans pt22 1 0) pttcv (trans pttcv 1 0))
  43.   (entmake (append '((0 . "SPLINE") (100 . "AcDbEntity") (100 . "AcDbSpline")) (list (cons 210 (trans '(0.0 0.0 1.0) 1 0 t))) '((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 pt11) (cons 41 1.0) (cons 10 pttcv) (cons 41 weightcv) (cons 10 pt22) (cons 41 1.0)) ))
  44.   (redraw)
  45.   (princ)
  46. )
  47.  

Thanks anyway for reading my initial post...
« Last Edit: February 27, 2015, 02:27:54 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube