TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ribarm on April 26, 2014, 09:14:01 AM

Title: EDGESURF
Post by: ribarm on April 26, 2014, 09:14:01 AM
Somehow, I can't find my old codes here on TheSwamp.org... I've done closest to built-in command, but just don't know why it isn't precise...

Here is my code, any suggestion to make it better are welcome...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:surfedge ( / osm c1 c2 c3 c4 m n _edges _pt lp1 lp2 lp3 lp4 i j pt1 pt2 pt3 pt4 )
  2.  
  3.  
  4.   (setq osm (getvar 'osmode))
  5.   (setvar 'osmode 0)
  6.   (while (not (setq c1 (car (entsel "\nPick 1st curve edge")))))
  7.   (while (not (setq c2 (car (entsel "\nPick 2nd curve edge")))))
  8.   (while (not (setq c3 (car (entsel "\nPick 3rd curve edge")))))
  9.   (while (not (setq c4 (car (entsel "\nPick 4th curve edge")))))
  10.   (initget 7)
  11.   (setq m (getint "\nSpecify number of segments along 1st and 3rd curves direction : "))
  12.   (initget 7)
  13.   (setq n (getint "\nSpecify number of segments along 2nd and 4th curves direction : "))
  14.  
  15.   (defun _edges ( c1 c2 c3 c4 m n / k mm nn lp1 lp2 lp3 lp4 )
  16.     (setq k -1)
  17.     (while (< k m)
  18.       (setq mm (cons (setq k (1+ k)) mm))
  19.     )
  20.     (setq k -1)
  21.     (while (< k n)
  22.       (setq nn (cons (setq k (1+ k)) nn))
  23.     )
  24.     (setq lp1 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c1 x))
  25.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c1) x))
  26.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c1) (vlax-curve-getstartparam c1)) x))
  27.                                          (mapcar '(lambda ( x ) (/ x (float m)))
  28.                                                   (reverse mm)
  29.                                          )
  30.                                 )
  31.                        )
  32.               )
  33.     )
  34.     (setq lp2 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c2 x))
  35.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c2) x))
  36.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c2) (vlax-curve-getstartparam c2)) x))
  37.                                          (mapcar '(lambda ( x ) (/ x (float n)))
  38.                                                   (reverse nn)
  39.                                          )
  40.                                 )
  41.                        )
  42.               )
  43.     )
  44.     (setq lp3 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c3 x))
  45.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c3) x))
  46.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c3) (vlax-curve-getstartparam c3)) x))
  47.                                          (mapcar '(lambda ( x ) (/ x (float m)))
  48.                                                   (reverse mm)
  49.                                          )
  50.                                 )
  51.                        )
  52.               )
  53.     )
  54.     (setq lp4 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c4 x))
  55.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c4) x))
  56.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c4) (vlax-curve-getstartparam c4)) x))
  57.                                          (mapcar '(lambda ( x ) (/ x (float n)))
  58.                                                   (reverse nn)
  59.                                          )
  60.                                 )
  61.                        )
  62.               )
  63.     )
  64.     (list lp1 lp2 lp3 lp4)
  65.   )
  66.  
  67.   (defun _pt ( lp1 lp2 lp3 lp4 a b / pt1 pt2 pt3 pt4 dzlp1 dzlp2 dzlp3 dzlp4 p1 p2 p3 p4 p1p p2p p3p p4p p1z p2z p3z p4z pp ppz pt )
  68.     (setq pt1 (nth 0 lp1))
  69.     (setq pt2 (nth 0 lp2))
  70.     (setq pt3 (nth 0 lp3))
  71.     (setq pt4 (nth 0 lp4))
  72.     (setq dzlp1 (mapcar '(lambda ( x ) (- (caddr x) (caddr (inters pt1 pt2 x (mapcar '+ x '(0.0 0.0 1.0)) nil)))) lp1))
  73.     (setq dzlp2 (mapcar '(lambda ( x ) (- (caddr x) (caddr (inters pt2 pt3 x (mapcar '+ x '(0.0 0.0 1.0)) nil)))) lp2))
  74.     (setq dzlp3 (mapcar '(lambda ( x ) (- (caddr x) (caddr (inters pt3 pt4 x (mapcar '+ x '(0.0 0.0 1.0)) nil)))) lp3))
  75.     (setq dzlp4 (mapcar '(lambda ( x ) (- (caddr x) (caddr (inters pt4 pt1 x (mapcar '+ x '(0.0 0.0 1.0)) nil)))) lp4))
  76.     (setq lp1 (mapcar '(lambda ( x y ) (mapcar '+ x (list 0.0 0.0 y))) lp1 dzlp1))
  77.     (setq lp2 (mapcar '(lambda ( x y ) (mapcar '+ x (list 0.0 0.0 y))) lp2 dzlp2))
  78.     (setq lp3 (mapcar '(lambda ( x y ) (mapcar '+ x (list 0.0 0.0 y))) lp3 dzlp3))
  79.     (setq lp4 (mapcar '(lambda ( x y ) (mapcar '+ x (list 0.0 0.0 y))) lp4 dzlp4))
  80.     (setq p1 (nth a lp1))
  81.     (setq p2 (nth b lp2))
  82.     (setq p3 (nth (- m a) lp3))
  83.     (setq p4 (nth (- n b) lp4))
  84.     (setq p1p (mapcar '- p1 (list 0.0 0.0 (setq p1z (caddr p1)))))
  85.     (setq p2p (mapcar '- p2 (list 0.0 0.0 (setq p2z (caddr p2)))))
  86.     (setq p3p (mapcar '- p3 (list 0.0 0.0 (setq p3z (caddr p3)))))
  87.     (setq p4p (mapcar '- p4 (list 0.0 0.0 (setq p4z (caddr p4)))))
  88.     (setq pp (inters p1p p3p p2p p4p t))
  89.     (setq ppz (/ (+ (* p1z (/ (- n b) (float n)))
  90.                     (* p2z (/ a (float m)))
  91.                     (* p3z (/ b (float n)))
  92.                     (* p4z (/ (- m a) (float m)))
  93.                  )  2.0
  94.               )
  95.     )
  96.     (setq pt (list (car pp) (cadr pp) ppz))
  97.     pt
  98.   )
  99.  
  100.   (setq lp1 (car (_edges c1 c2 c3 c4 m n)))
  101.   (setq lp2 (cadr (_edges c1 c2 c3 c4 m n)))
  102.   (setq lp3 (caddr (_edges c1 c2 c3 c4 m n)))
  103.   (setq lp4 (cadddr (_edges c1 c2 c3 c4 m n)))
  104.  
  105.   (setq i -1)
  106.   (repeat m
  107.     (setq j -1)
  108.     (setq i (1+ i))
  109.     (repeat n
  110.       (setq j (1+ j))
  111.       (setq pt1 (_pt lp1 lp2 lp3 lp4 i j))
  112.       (setq pt2 (_pt lp1 lp2 lp3 lp4 (1+ i) j))
  113.       (setq pt3 (_pt lp1 lp2 lp3 lp4 (1+ i) (1+ j)))
  114.       (setq pt4 (_pt lp1 lp2 lp3 lp4 i (1+ j)))
  115.       (command "_.3dface" pt1 pt2 pt3 pt4 "")
  116.     )
  117.   )
  118.  
  119.   (setvar 'osmode osm)
  120.   (princ)
  121. )
  122.  

M.R.
Title: Re: EDGESURF
Post by: ribarm on April 26, 2014, 04:11:04 PM
Now inside points aren't correct... Seems there is some other factor involved and I am missing it - look attached dwg...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:surfedge ( / osm c1 c2 c3 c4 m n _edges _pt lp1 lp2 lp3 lp4 i j pt1 pt2 pt3 pt4 )
  2.  
  3.  
  4.   (setq osm (getvar 'osmode))
  5.   (setvar 'osmode 0)
  6.   (while (not (setq c1 (car (entsel "\nPick 1st curve edge")))))
  7.   (while (not (setq c2 (car (entsel "\nPick 2nd curve edge")))))
  8.   (while (not (setq c3 (car (entsel "\nPick 3rd curve edge")))))
  9.   (while (not (setq c4 (car (entsel "\nPick 4th curve edge")))))
  10.   (initget 7)
  11.   (setq m (getint "\nSpecify number of segments along 1st and 3rd curves direction : "))
  12.   (initget 7)
  13.   (while (> (setq n (getint (strcat "\nSpecify number of segments along 2nd and 4th curves direction (must be <=" (itoa m) "): "))) m))
  14.  
  15.   (defun _edges ( c1 c2 c3 c4 m n / k mm nn lp1 lp2 lp3 lp4 )
  16.     (setq k -1)
  17.     (while (< k m)
  18.       (setq mm (cons (setq k (1+ k)) mm))
  19.     )
  20.     (setq k -1)
  21.     (while (< k n)
  22.       (setq nn (cons (setq k (1+ k)) nn))
  23.     )
  24.     (setq lp1 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c1 x))
  25.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c1) x))
  26.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c1) (vlax-curve-getstartparam c1)) x))
  27.                                          (mapcar '(lambda ( x ) (/ x (float m)))
  28.                                                   (reverse mm)
  29.                                          )
  30.                                 )
  31.                        )
  32.               )
  33.     )
  34.     (setq lp2 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c2 x))
  35.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c2) x))
  36.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c2) (vlax-curve-getstartparam c2)) x))
  37.                                          (mapcar '(lambda ( x ) (/ x (float n)))
  38.                                                   (reverse nn)
  39.                                          )
  40.                                 )
  41.                        )
  42.               )
  43.     )
  44.     (setq lp3 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c3 x))
  45.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c3) x))
  46.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c3) (vlax-curve-getstartparam c3)) x))
  47.                                          (mapcar '(lambda ( x ) (/ x (float m)))
  48.                                                   (reverse mm)
  49.                                          )
  50.                                 )
  51.                        )
  52.               )
  53.     )
  54.     (setq lp4 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c4 x))
  55.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c4) x))
  56.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c4) (vlax-curve-getstartparam c4)) x))
  57.                                          (mapcar '(lambda ( x ) (/ x (float n)))
  58.                                                   (reverse nn)
  59.                                          )
  60.                                 )
  61.                        )
  62.               )
  63.     )
  64.     (list lp1 lp2 lp3 lp4)
  65.   )
  66.  
  67.   (defun _pt ( lp1 lp2 lp3 lp4 a b / p1 p2 p3 p4 p1p p2p p3p p4p p1z p2z p3z p4z pp ppz pt )
  68.     (setq p1 (nth a lp1))
  69.     (setq p2 (nth b lp2))
  70.     (setq p3 (nth (- m a) lp3))
  71.     (setq p4 (nth (- n b) lp4))
  72.     (setq p1p (mapcar '- p1 (list 0.0 0.0 (setq p1z (caddr p1)))))
  73.     (setq p2p (mapcar '- p2 (list 0.0 0.0 (setq p2z (caddr p2)))))
  74.     (setq p3p (mapcar '- p3 (list 0.0 0.0 (setq p3z (caddr p3)))))
  75.     (setq p4p (mapcar '- p4 (list 0.0 0.0 (setq p4z (caddr p4)))))
  76.     (setq pp (inters p1p p3p p2p p4p t))
  77.     (setq ppz
  78.       (cond
  79.         ( (eq b 0)
  80.           p1z
  81.         )
  82.         ( (eq a 0)
  83.           p4z
  84.         )
  85.         ( (eq a m)
  86.           p2z
  87.         )
  88.         ( (eq b n)
  89.           p3z
  90.         )
  91.         ( t ;;; This formula is missing unknown factor ;;;
  92.           (/ (+ (* p1z (/ (- n b) (float n)))
  93.                 (* p2z (/ a (float m)))
  94.                 (* p3z (/ b (float n)))
  95.                 (* p4z (/ (- m a) (float m)))
  96.              )  2.0
  97.           )
  98.         )
  99.       )
  100.     )
  101.     (setq pt (list (car pp) (cadr pp) ppz))
  102.     pt
  103.   )
  104.  
  105.   (setq lp1 (car (_edges c1 c2 c3 c4 m n)))
  106.   (setq lp2 (cadr (_edges c1 c2 c3 c4 m n)))
  107.   (setq lp3 (caddr (_edges c1 c2 c3 c4 m n)))
  108.   (setq lp4 (cadddr (_edges c1 c2 c3 c4 m n)))
  109.  
  110.   (setq i -1)
  111.   (repeat m
  112.     (setq j -1)
  113.     (setq i (1+ i))
  114.     (repeat n
  115.       (setq j (1+ j))
  116.       (setq pt1 (_pt lp1 lp2 lp3 lp4 i j))
  117.       (setq pt2 (_pt lp1 lp2 lp3 lp4 (1+ i) j))
  118.       (setq pt3 (_pt lp1 lp2 lp3 lp4 (1+ i) (1+ j)))
  119.       (setq pt4 (_pt lp1 lp2 lp3 lp4 i (1+ j)))
  120.       (command "_.3dface" pt1 pt2 pt3 pt4 "")
  121.     )
  122.   )
  123.  
  124.   (setvar 'osmode osm)
  125.   (princ)
  126. )
  127.  

M.R.
Title: Re: EDGESURF
Post by: SEANT on April 27, 2014, 04:35:45 AM
See if the info in this thread is relevant.

http://www.cadtutor.net/forum/showthread.php?34410-Bilinear-Coons-Patch
Title: Re: EDGESURF
Post by: ribarm on April 27, 2014, 05:20:31 AM
See if the info in this thread is relevant.

http://www.cadtutor.net/forum/showthread.php?34410-Bilinear-Coons-Patch

This bilinear interpolation is exactly what I've used in posted example, but that's not solution... In my posted DWG you can see both variants - correct surface created with edgesurf command and my version using bilinear interpolation for inside points of surface... There is big difference between these two versions of surfaces... I just can't figure out what am I missing... :-(
Title: Re: EDGESURF
Post by: SEANT on April 27, 2014, 06:20:09 AM
The algorithm you've used seems pretty good - except for the Z value. 

The thread I linked shows a process that would help you correct that Z interpolation.  In the attached, add the Z component of the two CurveMidConnects midpoints (Yellow Points), and then subtract the Z value from the BiLinearMidConnect's midpoint (Magenta).  That value matches the associated EdgeSurf point (Cyan).
Title: Re: EDGESURF
Post by: ribarm on April 27, 2014, 06:35:43 AM
The algorithm you've used seems pretty good - except for the Z value. 

The thread I linked shows a process that would help you correct that Z interpolation.  In the attached, add the Z component of the two CurveMidConnects midpoints (Yellow Points), and then subtract the Z value from the BiLinearMidConnect's midpoint (Magenta).  That value matches the associated EdgeSurf point (Cyan).

OK, Sean, I'll try to implement this into my formula...
Title: Re: EDGESURF
Post by: ribarm on April 27, 2014, 07:06:21 AM
Your observation was correct Sean, just a small issue now p1e p2e p3e and p4e aren't coplanar - had to take z coordinate from interpolating z values of intersection of line p1e p3e and vertical line from point of projection pp; and from interpolating intersection of line p2e p4e and vertical line of projection point pp... Surface is now correct, except small differences along edges curves... But anyway thanks for your reply - I think I now understand those z coordinates better...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:surfedge ( / osm c1 c2 c3 c4 m n _edges _pt lp1 lp2 lp3 lp4 i j pt1 pt2 pt3 pt4 )
  2.  
  3.  
  4.   (setq osm (getvar 'osmode))
  5.   (setvar 'osmode 0)
  6.   (while (not (setq c1 (car (entsel "\nPick 1st curve edge")))))
  7.   (while (not (setq c2 (car (entsel "\nPick 2nd curve edge")))))
  8.   (while (not (setq c3 (car (entsel "\nPick 3rd curve edge")))))
  9.   (while (not (setq c4 (car (entsel "\nPick 4th curve edge")))))
  10.   (initget 7)
  11.   (setq m (getint "\nSpecify number of segments along 1st and 3rd curves direction : "))
  12.   (initget 7)
  13.   (setq n (getint "\nSpecify number of segments along 2nd and 4th curves direction : "))
  14.  
  15.   (defun _edges ( c1 c2 c3 c4 m n / k mm nn lp1 lp2 lp3 lp4 )
  16.     (setq k -1)
  17.     (while (< k m)
  18.       (setq mm (cons (setq k (1+ k)) mm))
  19.     )
  20.     (setq k -1)
  21.     (while (< k n)
  22.       (setq nn (cons (setq k (1+ k)) nn))
  23.     )
  24.     (setq lp1 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c1 x))
  25.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c1) x))
  26.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c1) (vlax-curve-getstartparam c1)) x))
  27.                                          (mapcar '(lambda ( x ) (/ x (float m)))
  28.                                                   (reverse mm)
  29.                                          )
  30.                                 )
  31.                        )
  32.               )
  33.     )
  34.     (setq lp2 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c2 x))
  35.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c2) x))
  36.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c2) (vlax-curve-getstartparam c2)) x))
  37.                                          (mapcar '(lambda ( x ) (/ x (float n)))
  38.                                                   (reverse nn)
  39.                                          )
  40.                                 )
  41.                        )
  42.               )
  43.     )
  44.     (setq lp3 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c3 x))
  45.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c3) x))
  46.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c3) (vlax-curve-getstartparam c3)) x))
  47.                                          (mapcar '(lambda ( x ) (/ x (float m)))
  48.                                                   (reverse mm)
  49.                                          )
  50.                                 )
  51.                        )
  52.               )
  53.     )
  54.     (setq lp4 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c4 x))
  55.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c4) x))
  56.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c4) (vlax-curve-getstartparam c4)) x))
  57.                                          (mapcar '(lambda ( x ) (/ x (float n)))
  58.                                                   (reverse nn)
  59.                                          )
  60.                                 )
  61.                        )
  62.               )
  63.     )
  64.     (list lp1 lp2 lp3 lp4)
  65.   )
  66.  
  67.   (defun _pt ( lp1 lp2 lp3 lp4 a b / p10 p20 p30 p40 p1 p2 p3 p4 p1p p2p p3p p4p p1z p2z p3z p4z p1e p2e p3e p4e p13ez p24ez pp ppez ppz pt )
  68.     (setq p10 (nth 0 lp1))
  69.     (setq p20 (nth 0 lp2))
  70.     (setq p30 (nth 0 lp3))
  71.     (setq p40 (nth 0 lp4))
  72.     (setq p1 (nth a lp1))
  73.     (setq p2 (nth b lp2))
  74.     (setq p3 (nth (- m a) lp3))
  75.     (setq p4 (nth (- n b) lp4))
  76.     (setq p1p (mapcar '- p1 (list 0.0 0.0 (setq p1z (caddr p1)))))
  77.     (setq p2p (mapcar '- p2 (list 0.0 0.0 (setq p2z (caddr p2)))))
  78.     (setq p3p (mapcar '- p3 (list 0.0 0.0 (setq p3z (caddr p3)))))
  79.     (setq p4p (mapcar '- p4 (list 0.0 0.0 (setq p4z (caddr p4)))))
  80.     (setq pp (inters p1p p3p p2p p4p t))
  81.     (setq p1e (inters p10 p20 p1p (mapcar '+ p1p '(0.0 0.0 1.0)) nil))
  82.     (setq p2e (inters p20 p30 p2p (mapcar '+ p2p '(0.0 0.0 1.0)) nil))
  83.     (setq p3e (inters p30 p40 p3p (mapcar '+ p3p '(0.0 0.0 1.0)) nil))
  84.     (setq p4e (inters p40 p10 p4p (mapcar '+ p4p '(0.0 0.0 1.0)) nil))
  85.     (setq p13ez (caddr (inters p1e p3e pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
  86.     (setq p24ez (caddr (inters p2e p4e pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
  87.     (setq ppez (/ (+ p13ez p24ez) 2.0))
  88.     (setq ppz (- (+ (* p1z (/ (- n b) (float n)))
  89.                     (* p2z (/ a (float m)))
  90.                     (* p3z (/ b (float n)))
  91.                     (* p4z (/ (- m a) (float m)))
  92.                  ) ppez
  93.               )
  94.     )
  95.     (setq pt (list (car pp) (cadr pp) ppz))
  96.     pt
  97.   )
  98.  
  99.   (setq lp1 (car (_edges c1 c2 c3 c4 m n)))
  100.   (setq lp2 (cadr (_edges c1 c2 c3 c4 m n)))
  101.   (setq lp3 (caddr (_edges c1 c2 c3 c4 m n)))
  102.   (setq lp4 (cadddr (_edges c1 c2 c3 c4 m n)))
  103.  
  104.   (setq i -1)
  105.   (repeat m
  106.     (setq j -1)
  107.     (setq i (1+ i))
  108.     (repeat n
  109.       (setq j (1+ j))
  110.       (setq pt1 (_pt lp1 lp2 lp3 lp4 i j))
  111.       (setq pt2 (_pt lp1 lp2 lp3 lp4 (1+ i) j))
  112.       (setq pt3 (_pt lp1 lp2 lp3 lp4 (1+ i) (1+ j)))
  113.       (setq pt4 (_pt lp1 lp2 lp3 lp4 i (1+ j)))
  114.       (command "_.3dface" pt1 pt2 pt3 pt4 "")
  115.     )
  116.   )
  117.  
  118.   (setvar 'osmode osm)
  119.   (princ)
  120. )
  121.  

Regards, M.R.
 :-)
Title: Re: EDGESURF
Post by: ribarm on April 27, 2014, 07:47:51 AM
Now the issue ab edges is solved - applied your method in entirety... But in comparison to original EDGESURF there are some differences with inside points... All in all this is now the best I've done...

Thanks a lot Sean T.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:surfedge ( / osm c1 c2 c3 c4 m n _edges _pt lp1 lp2 lp3 lp4 i j pt1 pt2 pt3 pt4 )
  2.  
  3.  
  4.   (setq osm (getvar 'osmode))
  5.   (setvar 'osmode 0)
  6.   (while (not (setq c1 (car (entsel "\nPick 1st curve edge")))))
  7.   (while (not (setq c2 (car (entsel "\nPick 2nd curve edge")))))
  8.   (while (not (setq c3 (car (entsel "\nPick 3rd curve edge")))))
  9.   (while (not (setq c4 (car (entsel "\nPick 4th curve edge")))))
  10.   (initget 7)
  11.   (setq m (getint "\nSpecify number of segments along 1st and 3rd curves direction : "))
  12.   (initget 7)
  13.   (setq n (getint "\nSpecify number of segments along 2nd and 4th curves direction : "))
  14.  
  15.   (defun _edges ( c1 c2 c3 c4 m n / k mm nn lp1 lp2 lp3 lp4 )
  16.     (setq k -1)
  17.     (while (< k m)
  18.       (setq mm (cons (setq k (1+ k)) mm))
  19.     )
  20.     (setq k -1)
  21.     (while (< k n)
  22.       (setq nn (cons (setq k (1+ k)) nn))
  23.     )
  24.     (setq lp1 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c1 x))
  25.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c1) x))
  26.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c1) (vlax-curve-getstartparam c1)) x))
  27.                                          (mapcar '(lambda ( x ) (/ x (float m)))
  28.                                                   (reverse mm)
  29.                                          )
  30.                                 )
  31.                        )
  32.               )
  33.     )
  34.     (setq lp2 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c2 x))
  35.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c2) x))
  36.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c2) (vlax-curve-getstartparam c2)) x))
  37.                                          (mapcar '(lambda ( x ) (/ x (float n)))
  38.                                                   (reverse nn)
  39.                                          )
  40.                                 )
  41.                        )
  42.               )
  43.     )
  44.     (setq lp3 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c3 x))
  45.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c3) x))
  46.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c3) (vlax-curve-getstartparam c3)) x))
  47.                                          (mapcar '(lambda ( x ) (/ x (float m)))
  48.                                                   (reverse mm)
  49.                                          )
  50.                                 )
  51.                        )
  52.               )
  53.     )
  54.     (setq lp4 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c4 x))
  55.                        (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c4) x))
  56.                                 (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c4) (vlax-curve-getstartparam c4)) x))
  57.                                          (mapcar '(lambda ( x ) (/ x (float n)))
  58.                                                   (reverse nn)
  59.                                          )
  60.                                 )
  61.                        )
  62.               )
  63.     )
  64.     (list lp1 lp2 lp3 lp4)
  65.   )
  66.  
  67.   (defun _pt ( lp1 lp2 lp3 lp4 a b / p10 p20 p30 p40 p1 p2 p3 p4 p1p p2p p3p p4p pp p1e p2e p3e p4e p13ez p24ez ppez p13z p24z ppz pt )
  68.     (setq p10 (nth 0 lp1))
  69.     (setq p20 (nth 0 lp2))
  70.     (setq p30 (nth 0 lp3))
  71.     (setq p40 (nth 0 lp4))
  72.     (setq p1 (nth a lp1))
  73.     (setq p2 (nth b lp2))
  74.     (setq p3 (nth (- m a) lp3))
  75.     (setq p4 (nth (- n b) lp4))
  76.     (setq p1p (mapcar '- p1 (list 0.0 0.0 (caddr p1))))
  77.     (setq p2p (mapcar '- p2 (list 0.0 0.0 (caddr p2))))
  78.     (setq p3p (mapcar '- p3 (list 0.0 0.0 (caddr p3))))
  79.     (setq p4p (mapcar '- p4 (list 0.0 0.0 (caddr p4))))
  80.     (setq pp (inters p1p p3p p2p p4p t))
  81.     (setq p1e (inters p10 p20 p1p (mapcar '+ p1p '(0.0 0.0 1.0)) nil))
  82.     (setq p2e (inters p20 p30 p2p (mapcar '+ p2p '(0.0 0.0 1.0)) nil))
  83.     (setq p3e (inters p30 p40 p3p (mapcar '+ p3p '(0.0 0.0 1.0)) nil))
  84.     (setq p4e (inters p40 p10 p4p (mapcar '+ p4p '(0.0 0.0 1.0)) nil))
  85.     (setq p13ez (caddr (inters p1e p3e pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
  86.     (setq p24ez (caddr (inters p2e p4e pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
  87.     (setq ppez (/ (+ p13ez p24ez) 2.0))
  88.     (setq p13z (caddr (inters p1 p3 pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
  89.     (setq p24z (caddr (inters p2 p4 pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
  90.     (setq ppz (- (+ p13z p24z) ppez))
  91.     (setq pt (list (car pp) (cadr pp) ppz))
  92.     pt
  93.   )
  94.  
  95.   (setq lp1 (car (_edges c1 c2 c3 c4 m n)))
  96.   (setq lp2 (cadr (_edges c1 c2 c3 c4 m n)))
  97.   (setq lp3 (caddr (_edges c1 c2 c3 c4 m n)))
  98.   (setq lp4 (cadddr (_edges c1 c2 c3 c4 m n)))
  99.  
  100.   (setq i -1)
  101.   (repeat m
  102.     (setq j -1)
  103.     (setq i (1+ i))
  104.     (repeat n
  105.       (setq j (1+ j))
  106.       (setq pt1 (_pt lp1 lp2 lp3 lp4 i j))
  107.       (setq pt2 (_pt lp1 lp2 lp3 lp4 (1+ i) j))
  108.       (setq pt3 (_pt lp1 lp2 lp3 lp4 (1+ i) (1+ j)))
  109.       (setq pt4 (_pt lp1 lp2 lp3 lp4 i (1+ j)))
  110.       (command "_.3dface" pt1 pt2 pt3 pt4 "")
  111.     )
  112.   )
  113.  
  114.   (setvar 'osmode osm)
  115.   (princ)
  116. )
  117.  

M.R.
 8-)
Title: Re: EDGESURF
Post by: liuhaixin88 on April 27, 2014, 07:49:49 AM
Nice , ribarm ,Can you pass a demo (GIF)
Title: Re: EDGESURF
Post by: ribarm on April 27, 2014, 08:09:31 AM
Nice , ribarm ,Can you pass a demo (GIF)

Just download my attached DWG, erase 3dface entities and surface created with edgesurf command... Start routine; pick curve1 - in frontal plane; pick curve2 - in right plane; pick curve3 - in back plane; pick curve4 - in left plane; Specify m divisions; specify n divisions and new surface made from 3dface entities will be created... Note that start-end points of curves must be connected in relation start/end => start/end => start/end => start/end - last end point of curve 4 is actually start point of curve 1 (c1=>c2=>c3=>c4) all start/end points direction must be CW or CCW... There must be no start/end => end/start...
Title: Re: EDGESURF
Post by: SEANT on April 27, 2014, 08:55:19 AM
Nicely done.
Title: Re: EDGESURF
Post by: myloveflyer on June 16, 2019, 10:07:58 PM
Nice , ribarm ,Can you pass a demo (GIF)

Just download my attached DWG, erase 3dface entities and surface created with edgesurf command... Start routine; pick curve1 - in frontal plane; pick curve2 - in right plane; pick curve3 - in back plane; pick curve4 - in left plane; Specify m divisions; specify n divisions and new surface made from 3dface entities will be created... Note that start-end points of curves must be connected in relation start/end => start/end => start/end => start/end - last end point of curve 4 is actually start point of curve 1 (c1=>c2=>c3=>c4) all start/end points direction must be CW or CCW... There must be no start/end => end/start...
HI,ribarm。There is a bit error in the running program. I don't know if I am drawing the problem. Please see the drawing in the attached file.
Title: Re: EDGESURF
Post by: roy_043 on June 18, 2019, 05:46:54 AM
@myloveflyer:
If you read ribarm's previous contribution carefully you will know why the right most example in your drawing fails.
1. You will need to _Mirror3d the biggest arc to ensure that all curves are in the correct start/end=>start/end sequence.
2. You will need to remove the small gaps between the lines and the biggest arc.

Note that if you remove the gaps the standard _EdgeSurf command should also work.
Title: Re: EDGESURF
Post by: myloveflyer on June 18, 2019, 09:51:55 PM
@myloveflyer:
If you read ribarm's previous contribution carefully you will know why the right most example in your drawing fails.
1. You will need to _Mirror3d the biggest arc to ensure that all curves are in the correct start/end=>start/end sequence.
2. You will need to remove the small gaps between the lines and the biggest arc.

Note that if you remove the gaps the standard _EdgeSurf command should also work.
Hi,Roy.Sure enough, there is no intersection. After I mirror the largest arc, the problem still exists. After I zoomed in on the Ribarm image 100 times, the program still appears "Error: parameter type error: 2D / 3D point: nil", I don't know. Why? Can you help me modify the program, I mainly use it for meshing.
Title: Re: EDGESURF
Post by: roy_043 on June 19, 2019, 05:05:05 AM
For my test I have used the test.dwg you have posted elsewhere:
https://www.cadtutor.net/forum/topic/67990-spatial-grid-segmentation/

Why the cross-posting?
Why the different dwgs?

See the modified dwg for what you should change in the dwg you have attached here.
As already explained the program has some restrictions. Maybe @ribarm will one day improve it.
Although the code is probably intended as more of an exercise than a finished product.

I advise you to use the built-in _EdgeSurf command instead.
Title: Re: EDGESURF
Post by: ribarm on June 19, 2019, 08:43:41 AM
I will not improve it more... I have working version for my purposes... What you should do to make it working is converting all curves to reverse possible curves - so arc should become spline - 2nd degree and planar curve... Then you should check for intersections at each end of curves and finally you should apply REVERSE command on those curves that don't satisfy rule of CCW as desired orientation... Finally you run routine and pick curves also in CCW manner... If there are no gaps between curves, routine should work and create desired result - mesh or (I forgot what... Polygon Mesh, Polyface Mesh, or...)
Title: Re: EDGESURF
Post by: myloveflyer on June 21, 2019, 11:48:35 PM
For my test I have used the test.dwg you have posted elsewhere:
https://www.cadtutor.net/forum/topic/67990-spatial-grid-segmentation/

Why the cross-posting?
Why the different dwgs?

See the modified dwg for what you should change in the dwg you have attached here.
As already explained the program has some restrictions. Maybe @ribarm will one day improve it.
Although the code is probably intended as more of an exercise than a finished product.

I advise you to use the built-in _EdgeSurf command instead.
Thank you, ROY. I have figured out how there will be a gap. When UCS converts, there is a problem with the capture. Thank you for your advice.
Title: Re: EDGESURF
Post by: myloveflyer on June 21, 2019, 11:55:35 PM
I will not improve it more... I have working version for my purposes... What you should do to make it working is converting all curves to reverse possible curves - so arc should become spline - 2nd degree and planar curve... Then you should check for intersections at each end of curves and finally you should apply REVERSE command on those curves that don't satisfy rule of CCW as desired orientation... Finally you run routine and pick curves also in CCW manner... If there are no gaps between curves, routine should work and create desired result - mesh or (I forgot what... Polygon Mesh, Polyface Mesh, or...)
Hi,ribarm.I have found the error of drawing under the guidance of roy. I don't know what your working version looks like. Can you provide it, is it also meshed? The current program is for quadrilateral meshes, in short, thank you for providing such a perfect program.