⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rutils.lsp

📁 Autocad-2005-简体中文-解密版.zip
💻 LSP
📖 第 1 页 / 共 5 页
字号:
;;;                  Required Functions:                               ;
;;;                      mult-by-scalar                                ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;               vect =  a valid vector list such as:                 ;
;;;                       '( 5 5 5 )                                   ;
;;;                                                                    ;
;;; Returned Value:  If the vector supplied is not '(0 0 0 )           ;
;;;                  A one unit vector is returned. Otherwise nil      ;
;;;                  is returned.                                      ;
;;;                                                                    ;
;;;			(unit-vector  '( 5 5 5))                       ;
;;;				Returns:                               ;
;;;				 (0.57735 0.57735 0.57735)             ;
;;;		                                                       ;
;;;          Usage: (unit-vector  '( 5 5 5))                           ;
;;;--------------------------------------------------------------------;
(defun unit-vector (vect / uv TransDataA TransData)

  (if (> (vlax-variant-type vect) 8192)
    (setq vect (vlax-safearray->list (vlax-variant-value vect)))
  )

  ;;; test for (0 0 0 )
  (setq uv (if (not (vl-every (function (lambda (x) (zerop x))) vect))
    (mult-by-scalar vect (/ 1.0 (vector-norm vect)))
    nil
    ))

;; Convert to a Variant Array of Doubles here ->
(if uv (progn
 (setq TransDataA (vlax-make-safearray vlax-vbDouble (cons 0 3)))
 (vlax-safearray-fill TransDataA uv)
 (setq TransData (vlax-make-variant TransDataA (logior vlax-vbarray vlax-vbDouble)))
))

)

;;;--------------------------------------------------------------------;
;;;       Function:  VECTOR-NORM                                       ;
;;;                                                                    ;
;;;    Description:  This function returns the normal for the          ;
;;;                  vector supplied.                                  ;
;;;                                                                    ;
;;;                  Required Functions:                               ;
;;;                      trace-vector                                  ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;               vect =  a valid vector list such as:                 ;
;;;                       '( 5 5 5 )                                   ;
;;;                                                                    ;
;;; Returned Value:  A number representing the normal of the vector.   ;
;;;		                                                       ;
;;;          Usage: (vector-norm '( 5 5 5))                            ;
;;;--------------------------------------------------------------------;
(defun vector-norm (vect / nv TransDataA TransData)

  (if (> (vlax-variant-type vect) 8192)
    (setq vect (vlax-safearray->list (vlax-variant-value vect)))
  )

  (setq nv (sqrt (trace-vector (mapcar '* vect vect))))

;; Convert to a Variant Array of Doubles here ->
(if nv (progn
 (setq TransDataA (vlax-make-safearray vlax-vbDouble (cons 0 3)))
 (vlax-safearray-fill TransDataA nv)
 (setq TransData (vlax-make-variant TransDataA (logior vlax-vbarray vlax-vbDouble)))
))

)


;;;--------------------------------------------------------------------;
;;;       Function:  TRACE-VECTOR                                      ;
;;;                                                                    ;
;;;    Description:  This function supplies the                        ;
;;;                  Sum of all the elements of a vector.              ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;               vect =  a valid vector list such as:                 ;
;;;                       '( 5 5 5 )                                   ;
;;;                                                                    ;
;;; Returned Value:  A number representing the xxxxxx of the vector.   ;
;;;		                                                       ;
;;;          Usage: (trace-vector '( 5 5 5))                           ;
;;;--------------------------------------------------------------------;
(defun trace-vector (vect)

  (if (> (vlax-variant-type vect) 8192)
    (setq vect (vlax-safearray->list (vlax-variant-value vect)))
  )

  (if (null vect)
    0
    (+ (car vect) (trace-vector (cdr vect)))
  )

)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Matrix Operations                                                 ;
;;;--------------------------------------------------------------------;
;;;       Function:  CHECK-VECTOR-ELEM                                 ;
;;;                                                                    ;
;;;    Description:  This function check the integrity of the elem     ;
;;;                  argument. This guarantees a number value for      ;
;;;                  functions that require this check.                ;
;;;                                                                    ;
;;;                  Required Functions:                               ;
;;;                      check-vector-elem                             ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;               elem =  a valid number or nil                        ;
;;;                                                                    ;
;;; Returned Value:  A number. If the argument elem is nil.            ;
;;;                  check-vector returns 0 otherwise it returns the   ;
;;;                  argument.                                         ;
;;;		                                                       ;
;;;          Usage: (check-vector-elem 0)                              ;
;;;--------------------------------------------------------------------;
(defun check-vector-elem (elem)
  (if (null elem)
    0
    elem
  )
)

;;;--------------------------------------------------------------------;
;;;       Function:  MAKE-TRANSLATION-MATRIX                           ;
;;;                                                                    ;
;;;    Description:  This function converts a variant vector list      ;
;;;                  (a list of three numbers) into a vector matrix.   ;
;;;                                                                    ;
;;;                  Required Functions:                               ;
;;;                                                                    ;
;;;                                                                    ;
;;;                  Example:  A vector list '( 5 5 5 ) is passed to   ;
;;;                  make-translation-matrix. The function then        ;
;;;                  translates this value to a matrix list.           ;
;;;                  using the following logic.                        ;
;;;                                                                    ;
;;;			make a translation matrix from                 ;
;;;			1,2 or 3 dim vector v represented as:          ;
;;;			 	list (x), (x y) or (x y z)             ;
;;;                                                                    ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;             vector =  a valid vector list such as:                 ;
;;;                       '( 5 5 5) or '( 1.2 4.5 200.00)              ;
;;;      or vector =  a valid safearray variant vector list of doubles ;
;;;                                                                    ;
;;; Returned Value:  A matrix List such as:                            ;
;;;		      (make-translation-matrix '( 5 5 5 ))             ;
;;;		                                                       ;
;;;		            Returns List In A Variant Array:           ;
;;;				((1.0 0.0 0.0 5.0)                     ;
;;;				  (0.0 1.0 0.0 5.0)                    ;
;;;				  (0.0 0.0 1.0 5.0)                    ;
;;;				  (0.0 0.0 0.0 1.0)                    ;
;;;				)                                      ;
;;;		                                                       ;
;;;       Usage: (make-translation-matrix '( 5 5 5 ))   or             ;
;;;              (make-translation-matrix (vlax-3d-point '( 5 5 5 )))  ;
;;;                                                                    ;
;;;--------------------------------------------------------------------;
(defun make-translation-matrix (vector)

  (if (> (vlax-variant-type vector) 8192)
    (setq vector (vlax-safearray->list (vlax-variant-value vector)))
  )

  (setq tm (vlax-tmatrix
    (list (list 1 0 0 (car vector))
          (list 0 1 0 (check-vector-elem (cadr vector)))
          (list 0 0 1 (check-vector-elem (caddr vector)))
          '(0 0 0 1)
    )
  ))

;; Convert to a Variant Array of Doubles here ->
 (setq TransDataA (vlax-make-safearray vlax-vbDouble (cons 0 3) (cons 0 3)))
 (vlax-safearray-fill TransDataA tm)
 (setq TransData (vlax-make-variant TransDataA (logior vlax-vbarray vlax-vbDouble)))

)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Vla-Object Transformation Functions                                ;
;;;--------------------------------------------------------------------;
;;;       Function:  TRANSLATE-VLA-OBJECT                              ;
;;;                                                                    ;
;;;    Description:  This function translates the current              ;
;;;                  transformation values of an object by a supplied  ;
;;;                  vector list.  This vector list is a list of three ;
;;;                  numbers which determine the new values for the    ;
;;;                  existing transformation value.                    ;
;;;                  Translate-Vla-Object is similar to                ;
;;;                  translate-object except this function performs    ;
;;;                  error checking before passing the information     ;
;;;                  to translate-object.                              ;
;;;                                                                    ;
;;;                  Note: This function performs                      ;
;;;                        error checking.                             ;
;;;                                                                    ;
;;;                  Required Functions:                               ;
;;;                      translate-object                              ;
;;;                                                                    ;
;;;                  Example:  A line beginning is anchored at 0,0,0.  ;
;;;                  Its ending point is 1,0,0. The transformation     ;
;;;                  value is '(5 5 5). Hence add 5 to the X value, 5  ;
;;;                  to the Y value and 5 to the Z value. The result   ;
;;;                  will be:                                          ;
;;;                       The beginning point will have 5,5,5          ;
;;;                       The ending point will have 6,5,5             ;
;;;                                                                    ;
;;;                  The example above demonstrates a different method ;
;;;                  for moving an object.                             ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;           vla-obj  =  a vla object that can contain                ;
;;;                       transformation verctors.                     ;
;;; translation-vector =  a valid vector list such as:                 ;
;;;                       '( 5 5 5) or '( 1.2 4.5 200.00)              ;
;;;                                                                    ;
;;;                                                                    ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -