Jump to content

Recommended Posts

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • eimimitu

    12

  • Hippe013

    5

  • rlx

    4

  • poulhein

    2

Posted (edited)
That's what it's looking like... That said how do i determine rotation of each axis based on the normal vector? haven't been able to figure it out by experimenting...

 

Hi, Do you mean

command: ALIGN ?

But if the region gets normalized '(0.0 0.0 1.0), looks weird like this because of flatten

 

Q01QtWh.png

 

p/s: bugs ac2007-2012

Edited by hanhphuc
[IMG]
Posted

Here, try this... I only partially read topic, but if you want to align REGION to WCS plane you can do it with following code (still normal vector not exactly (0.0 0.0 1.0), but REGION is assumed that lie in WCS as there is Centroid and other previously missing properties...) :

 

(defun c:normalizeregion ( / unit v^v LM:InverseMatrix reg n x y z p elev m )

 (vl-load-com)

 (defun unit ( v / d )
   (if (not (equal (setq d (distance '(0.0 0.0 0.0) v)) 0.0 1e-)
     (mapcar '(lambda ( x ) (/ x d)) v)
   )
 )

 (defun v^v ( u v )
   (list
     (- (* (cadr u) (caddr v)) (* (caddr u) (cadr v)))
     (- (* (caddr u) (car v)) (* (car u) (caddr v)))
     (- (* (car u) (cadr v)) (* (cadr u) (car v)))
   )
 )

 ;;--------------------=={ Inverse Matrix }==------------------;;
 ;;                                                            ;;
 ;;  Implements the Gauss-Jordan Elimination algorithm to      ;;
 ;;  inverse a non-singular nxn matrix.                        ;;
 ;;------------------------------------------------------------;;
 ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
 ;;------------------------------------------------------------;;
 ;;  Arguments: m - nxn Matrix                                 ;;
 ;;------------------------------------------------------------;;
 ;;  Returns:  Matrix inverse, or nil if matrix is singular    ;;
 ;;------------------------------------------------------------;;

 (defun LM:InverseMatrix ( m / _identity _eliminate p r x )

   (defun _identity ( n / i j l m ) (setq i 1)
     (repeat n (setq j 0)
       (repeat n
         (setq l (cons (if (= i (setq j (1+ j))) 1. 0.) l))
       )
       (setq m (cons l m) l nil i (1+ i)) m
     )
   )

   (defun _eliminate ( m p )
     (mapcar
       (function
         (lambda ( x / d )
           (setq d (car x)) (mapcar (function (lambda ( a b ) (- a (* d b)))) (cdr x) p)
         )
       )
       m
     )
   )
   (setq m (mapcar 'append m (_identity (length m))))
   
   (while m
     (setq p (apply 'max (mapcar 'abs (mapcar 'car m))))
     (while (not (equal p (abs (caar m)) 1e-14))
       (setq m (append (cdr m) (list (car m))))
     )
     (if (equal 0.0 (caar m) 1e-14)
       (setq m nil)
       (setq p (/ 1. (caar m))
             p (mapcar (function (lambda ( x ) (* p x))) (cdar m))
             m (_eliminate (cdr m) p)
             r (cons p (_eliminate r p))
       )
     )
   )
   (reverse r)
 )

 (while (or (not (setq reg (car (entsel "\nPick REGION to normalize it with WCS z vector '(0.0 0.0 1.0)...")))) (if reg (/= (cdr (assoc 0 (entget reg))) "REGION")))
   (prompt "\nMissed or picked wrong entity type...")
 )
 (setq n (vlax-safearray->list (vlax-variant-value (vla-get-normal (vlax-ename->vla-object reg)))))
 (setq x (if (equal n '(0.0 0.0 1.0) 1e-6) '(1.0 0.0 0.0)))
 (setq y (if (equal n '(0.0 0.0 1.0) 1e-6) '(0.0 1.0 0.0)))
 (if (and (null x) (equal n '(0.0 0.0 -1.0) 1e-6))
   (setq x '(-1.0 0.0 0.0))
 )
 (if (and (null y) (equal n '(0.0 0.0 -1.0) 1e-6))
   (setq y '(0.0 1.0 0.0))
 )
 (if (null x)
   (setq x (unit (v^v '(0.0 0.0 1.0) n)))
 )
 (if (null y)
   (setq y (unit (v^v n x)))
 )
 (setq z n)
 (vl-cmdf "_.EXPLODE" reg)
 (while (< 0 (getvar 'cmdactive)) (vl-cmdf ""))
 (setq p (vlax-curve-getstartpoint (entlast)))
 (vl-cmdf "_.UNDO" "1")
 (setq elev (caddr (trans p 0 n)))
 (setq m (list (list (car x) (car y) (car z) 0.0) (list (cadr x) (cadr y) (cadr z) 0.0) (list (caddr x) (caddr y) (caddr z) 0.0) (list 0.0 0.0 0.0 1.0)))
 (vla-transformby (vlax-ename->vla-object reg) (vlax-tmatrix (LM:InverseMatrix m)))
 (vla-move (vlax-ename->vla-object reg) (vlax-3d-point (list 0.0 0.0 elev)) (vlax-3d-point '(0.0 0.0 0.0)))
 (princ)
)

 

HTH., M.R.

Posted

that works Marko... thank you much...

 

now off to figure out how it does it! :D

 

Thanks to all the contributors...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...