Author Topic: EVOLUTE LWPOLYLINE on planar SPLINE  (Read 1576 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
EVOLUTE LWPOLYLINE on planar SPLINE
« on: March 29, 2014, 10:55:16 AM »
Inspired with this topic :
http://www.theswamp.org/index.php?topic=46641.0

I wrote this code for evolute :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:splcencurvpol-evolute ( / getvertices v^v unit osm spl pl ptlst n opn ptlstn )
  2.  
  3.  
  4.   (defun getvertices ( pl / k pt ptlst )
  5.     (if (zerop (logand (cdr (assoc 70 (entget pl))) 1))
  6.       (progn
  7.         (setq k -1.0)
  8.         (repeat (1+ (fix (vlax-curve-getendparam pl)))
  9.           (setq pt (vlax-curve-getpointatparam pl (setq k (1+ k))))
  10.           (setq ptlst (cons pt ptlst))
  11.         )
  12.       )
  13.       (progn
  14.         (setq k -1.0)
  15.         (repeat (fix (vlax-curve-getendparam pl))
  16.           (setq pt (vlax-curve-getpointatparam pl (setq k (1+ k))))
  17.           (setq ptlst (cons pt ptlst))
  18.         )
  19.       )
  20.     )
  21.     (reverse ptlst)
  22.   )
  23.  
  24.   (defun v^v ( u v / cda )
  25.     (defun cda ( p ) (cdr (append p p)))
  26.     (mapcar '- (mapcar '* (cda u) (cdr (cda v))) (mapcar '* (cdr (cda u)) (cda v)) '(0.0 0.0 0.0))
  27.   )
  28.  
  29.   (defun unit ( v )
  30.     (mapcar '(lambda ( x ) (/ x (distance '(0.0 0.0 0.0) v))) v)
  31.   )
  32.  
  33.   (setq osm (getvar 'osmode))
  34.   (setvar 'osmode 0)
  35.   (command "_.ucs" "_W")
  36.   (prompt "\nPick SPLINE")
  37.   (while (not (eq (if (setq spl (car (entsel))) (cdr (assoc 0 (entget spl))) nil) "SPLINE"))
  38.     (prompt "\nPicked entity isn't SPLINE, or missed... Try again...")
  39.   )
  40.     (progn
  41.       (command "_.splinedit" spl "_P" "\\")
  42.       (setq pl (entlast))
  43.       (setq ptlst (getvertices pl))
  44.       (setq n (v^v (mapcar '- (cadr ptlst) (car ptlst)) (mapcar '- (caddr ptlst) (car ptlst))))
  45.       (setq opn (zerop (logand (cdr (assoc 70 (entget pl))) 1)))
  46.       (if opn
  47.         (progn
  48.           (mapcar
  49.           '(lambda ( v1 v2 / v1vec v2vec ip )
  50.             (cond
  51.               ( (equal v1 (vlax-curve-getstartpoint spl) 1e-3)
  52.                 (setq ptlstn (cons v1 ptlstn))
  53.                 (setq v1vec (vlax-curve-getfirstderiv spl (vlax-curve-getparamatpoint spl v1)))
  54.                 (setq v1vec (v^v v1vec n))
  55.                 (setq v2vec (vlax-curve-getfirstderiv spl (vlax-curve-getparamatpoint spl v2)))
  56.                 (setq v2vec (v^v v2vec n))
  57.                 (setq ip (inters v1 (mapcar '+ v1 v1vec) v2 (mapcar '+ v2 v2vec) nil))
  58.                 (setq ptlstn (cons ip ptlstn))
  59.               )
  60.               ( (and (not (equal v1 (vlax-curve-getstartpoint spl) 1e-3))
  61.                      (not (equal v2 (vlax-curve-getendpoint spl) 1e-3))
  62.                 )
  63.                 (setq v1vec (vlax-curve-getfirstderiv spl (vlax-curve-getparamatpoint spl v1)))
  64.                 (setq v1vec (v^v v1vec n))
  65.                 (setq v2vec (vlax-curve-getfirstderiv spl (vlax-curve-getparamatpoint spl v2)))
  66.                 (setq v2vec (v^v v2vec n))
  67.                 (setq ip (inters v1 (mapcar '+ v1 v1vec) v2 (mapcar '+ v2 v2vec) nil))
  68.                 (setq ptlstn (cons ip ptlstn))
  69.               )
  70.               ( (equal v2 (vlax-curve-getendpoint spl) 1e-3)
  71.                 (setq v1vec (vlax-curve-getfirstderiv spl (vlax-curve-getparamatpoint spl v1)))
  72.                 (setq v1vec (v^v v1vec n))
  73.                 (setq v2vec (vlax-curve-getfirstderiv spl (vlax-curve-getparamatpoint spl v2)))
  74.                 (setq v2vec (v^v v2vec n))
  75.                 (setq ip (inters v1 (mapcar '+ v1 v1vec) v2 (mapcar '+ v2 v2vec) nil))
  76.                 (setq ptlstn (cons ip ptlstn))
  77.                 (setq ptlstn (cons v2 ptlstn))
  78.               )
  79.             )
  80.            )
  81.            ptlst
  82.            (cdr ptlst)
  83.           )
  84.         )
  85.         (progn
  86.           (mapcar
  87.           '(lambda ( v1 v2 / v1vec v2vec ip )
  88.               (progn
  89.                 (setq v1vec (vlax-curve-getfirstderiv spl (vlax-curve-getparamatpoint spl v1)))
  90.                 (setq v1vec (v^v v1vec n))
  91.                 (setq v2vec (vlax-curve-getfirstderiv spl (vlax-curve-getparamatpoint spl v2)))
  92.                 (setq v2vec (v^v v2vec n))
  93.                 (setq ip (inters v1 (mapcar '+ v1 v1vec) v2 (mapcar '+ v2 v2vec) nil))
  94.                 (setq ptlstn (cons ip ptlstn))
  95.               )
  96.            )
  97.            (reverse (cdr (reverse ptlst)))
  98.            (cdr (reverse (cons (car ptlst) (reverse ptlst))))
  99.           )
  100.         )
  101.       )
  102.       (setq ptlstn (vl-remove nil ptlstn))
  103.       (entmake  (append
  104.                   (list
  105.                    '(0 . "LWPOLYLINE")
  106.                    '(100 . "AcDbEntity")
  107.                    '(100 . "AcDbPolyline")
  108.                     (cons 90 (length ptlstn))
  109.                     (if opn (cons 70 128) (cons 70 129))
  110.                     (cons 38 (caddr (trans (car ptlstn) 0 n)))
  111.                   )
  112.                   (mapcar '(lambda ( x ) (cons 10 (list (car (trans x 0 n)) (cadr (trans x 0 n))))) (reverse ptlstn))
  113.                   (list (cons 210 (unit n)))
  114.                 )
  115.       )
  116.       (entdel pl)
  117.     )
  118.     (progn
  119.       (alert "Picked SPLINE entity isn't planar... Quitting...")
  120.       (exit)
  121.     )
  122.   )
  123.   (command "_.ucs" "_P")
  124.   (setvar 'osmode osm)
  125.   (princ)
  126. )
  127.  

It works on my machine, and for Quirkiness and such problems if exist refer to my link posted above...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: EVOLUTE LWPOLYLINE on planar SPLINE
« Reply #1 on: March 29, 2014, 10:57:47 AM »
And this one is the same as for tangents LWPOLYLINE, except (vlax-curve-getfirstderiv) function was changed in all places with (vlax-curve-getsecondderiv)... Watch how different curvature can be made from planar SPLINE...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:splsecderivpol ( / getvertices v^v unit osm spl pl ptlst n opn ptlstn )
  2.  
  3.  
  4.   (defun getvertices ( pl / k pt ptlst )
  5.     (if (zerop (logand (cdr (assoc 70 (entget pl))) 1))
  6.       (progn
  7.         (setq k -1.0)
  8.         (repeat (1+ (fix (vlax-curve-getendparam pl)))
  9.           (setq pt (vlax-curve-getpointatparam pl (setq k (1+ k))))
  10.           (setq ptlst (cons pt ptlst))
  11.         )
  12.       )
  13.       (progn
  14.         (setq k -1.0)
  15.         (repeat (fix (vlax-curve-getendparam pl))
  16.           (setq pt (vlax-curve-getpointatparam pl (setq k (1+ k))))
  17.           (setq ptlst (cons pt ptlst))
  18.         )
  19.       )
  20.     )
  21.     (reverse ptlst)
  22.   )
  23.  
  24.   (defun v^v ( u v / cda )
  25.     (defun cda ( p ) (cdr (append p p)))
  26.     (mapcar '- (mapcar '* (cda u) (cdr (cda v))) (mapcar '* (cdr (cda u)) (cda v)) '(0.0 0.0 0.0))
  27.   )
  28.  
  29.   (defun unit ( v )
  30.     (mapcar '(lambda ( x ) (/ x (distance '(0.0 0.0 0.0) v))) v)
  31.   )
  32.  
  33.   (setq osm (getvar 'osmode))
  34.   (setvar 'osmode 0)
  35.   (command "_.ucs" "_W")
  36.   (prompt "\nPick SPLINE")
  37.   (while (not (eq (if (setq spl (car (entsel))) (cdr (assoc 0 (entget spl))) nil) "SPLINE"))
  38.     (prompt "\nPicked entity isn't SPLINE, or missed... Try again...")
  39.   )
  40.     (progn
  41.       (command "_.splinedit" spl "_P" "\\")
  42.       (setq pl (entlast))
  43.       (setq ptlst (getvertices pl))
  44.       (setq n (v^v (mapcar '- (cadr ptlst) (car ptlst)) (mapcar '- (caddr ptlst) (car ptlst))))
  45.       (setq opn (zerop (logand (cdr (assoc 70 (entget pl))) 1)))
  46.       (if opn
  47.         (progn
  48.           (mapcar
  49.           '(lambda ( v1 v2 / v1vec v2vec ip )
  50.             (cond
  51.               ( (equal v1 (vlax-curve-getstartpoint spl) 1e-3)
  52.                 (setq ptlstn (cons v1 ptlstn))
  53.                 (setq v1vec (vlax-curve-getsecondderiv spl (vlax-curve-getparamatpoint spl v1)))
  54.                 (setq v2vec (vlax-curve-getsecondderiv spl (vlax-curve-getparamatpoint spl v2)))
  55.                 (setq ip (inters v1 (mapcar '+ v1 v1vec) v2 (mapcar '+ v2 v2vec) nil))
  56.                 (setq ptlstn (cons ip ptlstn))
  57.               )
  58.               ( (and (not (equal v1 (vlax-curve-getstartpoint spl) 1e-3))
  59.                      (not (equal v2 (vlax-curve-getendpoint spl) 1e-3))
  60.                 )
  61.                 (setq v1vec (vlax-curve-getsecondderiv spl (vlax-curve-getparamatpoint spl v1)))
  62.                 (setq v2vec (vlax-curve-getsecondderiv spl (vlax-curve-getparamatpoint spl v2)))
  63.                 (setq ip (inters v1 (mapcar '+ v1 v1vec) v2 (mapcar '+ v2 v2vec) nil))
  64.                 (setq ptlstn (cons ip ptlstn))
  65.               )
  66.               ( (equal v2 (vlax-curve-getendpoint spl) 1e-3)
  67.                 (setq v1vec (vlax-curve-getsecondderiv spl (vlax-curve-getparamatpoint spl v1)))
  68.                 (setq v2vec (vlax-curve-getsecondderiv spl (vlax-curve-getparamatpoint spl v2)))
  69.                 (setq ip (inters v1 (mapcar '+ v1 v1vec) v2 (mapcar '+ v2 v2vec) nil))
  70.                 (setq ptlstn (cons ip ptlstn))
  71.                 (setq ptlstn (cons v2 ptlstn))
  72.               )
  73.             )
  74.            )
  75.            ptlst
  76.            (cdr ptlst)
  77.           )
  78.         )
  79.         (progn
  80.           (mapcar
  81.           '(lambda ( v1 v2 / v1vec v2vec ip )
  82.               (progn
  83.                 (setq v1vec (vlax-curve-getsecondderiv spl (vlax-curve-getparamatpoint spl v1)))
  84.                 (setq v2vec (vlax-curve-getsecondderiv spl (vlax-curve-getparamatpoint spl v2)))
  85.                 (setq ip (inters v1 (mapcar '+ v1 v1vec) v2 (mapcar '+ v2 v2vec) nil))
  86.                 (setq ptlstn (cons ip ptlstn))
  87.               )
  88.            )
  89.            (reverse (cdr (reverse ptlst)))
  90.            (cdr (reverse (cons (car ptlst) (reverse ptlst))))
  91.           )
  92.         )
  93.       )
  94.       (setq ptlstn (vl-remove nil ptlstn))
  95.       (entmake  (append
  96.                   (list
  97.                    '(0 . "LWPOLYLINE")
  98.                    '(100 . "AcDbEntity")
  99.                    '(100 . "AcDbPolyline")
  100.                     (cons 90 (length ptlstn))
  101.                     (if opn (cons 70 128) (cons 70 129))
  102.                     (cons 38 (caddr (trans (car ptlstn) 0 n)))
  103.                   )
  104.                   (mapcar '(lambda ( x ) (cons 10 (list (car (trans x 0 n)) (cadr (trans x 0 n))))) (reverse ptlstn))
  105.                   (list (cons 210 (unit n)))
  106.                 )
  107.       )
  108.       (entdel pl)
  109.     )
  110.     (progn
  111.       (alert "Picked SPLINE entity isn't planar... Quitting...")
  112.       (exit)
  113.     )
  114.   )
  115.   (command "_.ucs" "_P")
  116.   (setvar 'osmode osm)
  117.   (princ)
  118. )
  119.  

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

:)

M.R. on Youtube