TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: lamarn on November 18, 2009, 03:44:08 PM

Title: Mesh from listed x,y,z
Post by: lamarn on November 18, 2009, 03:44:08 PM
I'm looking for a way to make a surface,mesh for the points listed below?
Does anybody have a clue how to to this in Autocad (.. not Civil or MAP)?
Is it possible?

Thanks in regard

x,y,z
187102.50,420037.50,3.42
187107.50,420037.50,3.40
187112.50,420037.50,3.39
187097.50,420042.50,3.55
187102.50,420042.50,3.38
187107.50,420042.50,3.39
187112.50,420042.50,3.44
187097.50,420047.50,3.45
187102.50,420047.50,3.38
187107.50,420047.50,3.40
187112.50,420047.50,3.55
187097.50,420052.50,3.61
187102.50,420052.50,3.65
187107.50,420052.50,3.45
187092.50,420057.50,3.40
187097.50,420057.50,3.42
187102.50,420057.50,3.51
187107.50,420057.50,3.58
187092.50,420062.50,3.54
187097.50,420062.50,3.49
Title: Re: Mesh from listed x,y,z
Post by: Lee Mac on November 18, 2009, 05:36:34 PM
Quick example:

Code: [Select]
(defun Mk_mesh (lst m n)
  (vl-load-com)

  (vla-add3DMesh
    (vla-get-ModelSpace
      (vla-get-ActiveDocument
        (vlax-get-acad-object))) m n
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray
          vlax-vbDouble (cons 0 (1- (* 3 m n))))
        (apply 'append lst)))))

(defun c:test ( )

  (Mk_mesh

    '(
      (187102.50 420037.50 3.42)
      (187107.50 420037.50 3.40)
      (187112.50 420037.50 3.39)
      (187097.50 420042.50 3.55)
      (187102.50 420042.50 3.38)
      (187107.50 420042.50 3.39)
      (187112.50 420042.50 3.44)
      (187097.50 420047.50 3.45)
      (187102.50 420047.50 3.38)
      (187107.50 420047.50 3.40)
      (187112.50 420047.50 3.55)
      (187097.50 420052.50 3.61)
      (187102.50 420052.50 3.65)
      (187107.50 420052.50 3.45)
      (187092.50 420057.50 3.40)
      (187097.50 420057.50 3.42)
      (187102.50 420057.50 3.51)
      (187107.50 420057.50 3.58)
      (187092.50 420062.50 3.54)
      (187097.50 420062.50 3.49)
     )

    5 4)

  (princ))
Title: Re: Mesh from listed x,y,z
Post by: Lee Mac on November 18, 2009, 07:43:39 PM
Speaking of Meshes, this is one if my favourite Mathematical surfaces   :-)

Code: [Select]
(defun c:saddle (/ xMin xMax yMin yMax xInc yInc x y lst)
  (vl-load-com)

  (setq xMin -10 xMax 10
        yMin -10 yMax 10

        xInc 1 yInc 1)

  (setq x (- xMin xInc))
  (while (<= (setq x (+ xInc x)) xMax)

    (setq y (- yMin yInc))
    (while (<= (setq y (+ yInc y)) yMax)

      (setq lst (append (list x y (- (* x x) (* y y))) lst))))

  (vla-add3Dmesh
    (vla-get-ModelSpace
      (vla-get-ActiveDocument
        (vlax-get-acad-object))) 21 21
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray
          vlax-VbDouble
          (cons 0 (1- (fix (* (/ (1+ (- xMax xMin)) (float xInc))
                              (/ (1+ (- yMax yMin)) (float yInc)) 3))))) lst)))

  (princ))
Title: Re: Mesh from listed x,y,z
Post by: DEVITG on November 22, 2009, 06:50:30 PM
Hi Lee Mac , nice work .
Title: Re: Mesh from listed x,y,z
Post by: Lee Mac on November 22, 2009, 07:06:39 PM
Hi Lee Mac , nice work .


Thanks Mr Devit :-)
Title: Re: Mesh from listed x,y,z
Post by: lamarn on November 23, 2009, 03:55:18 PM
Thank Lee mac,
The surface is not logical but the saddle looks nice !
Title: Re: Mesh from listed x,y,z
Post by: Lee Mac on November 23, 2009, 07:19:56 PM
Thank Lee mac,
The surface is not logical but the saddle looks nice !

I did not know of the dimensions you wanted for the surface - so I guess 5x4  :|
Title: Re: Mesh from listed x,y,z
Post by: lamarn on November 24, 2009, 04:51:47 PM
I want to create a surface that is defined witg these points, for example

(x,y,z)

3,1,3
2,4,6
5,6,3
7,3,9
7,5,7

can you drape this surface with code?
 
Title: Re: Mesh from listed x,y,z
Post by: Lee Mac on November 24, 2009, 04:56:26 PM
There needs to be a number of points that has a factor that is greater than or equal to 2, - hence 5 points will not work... 4 will though.
Title: Re: Mesh from listed x,y,z
Post by: Lee Mac on November 24, 2009, 05:14:09 PM
For example for 2x2:

Code: [Select]
(defun Mk_mesh (lst m n)
  (vl-load-com)

  (vla-add3DMesh
    (vla-get-ModelSpace
      (vla-get-ActiveDocument
        (vlax-get-acad-object))) m n
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray
          vlax-vbDouble (cons 0 (1- (* 3 m n))))
        (apply 'append lst)))))
Code: [Select]
(defun c:test ( )

  (Mk_mesh

    '((3 1 3)
      (2 4 6)
      (5 6 3)
      (7 3 9)
      ;(7 5 7)
      )

    2 2)

  (princ))