如果您知道块坐标系中点的坐标(以下示例中的POC),或者可以获得它们,则可以将点的齐次坐标乘以矩阵。我的矩阵乘法函数没有其他函数那么优雅,但它可以工作。
- (defun c:tt (/)
- (setq pOCS '(1.11 2.22 3.33)) ; coordinates in Object Cor. Sys
- (setq M (cadr (cdr (nentsel)) )) ; block 4 x 3 matrix
- (setq pWCS (transform pOCS M)) ; coordinates in WCS
- (princ pwcs)
- (princ)
- )
- (defun transform (a HTM / transpt) ;Coordinate transformation via matrix multiplication
- ; a = point (3 coordinates)
- ; HTM = homogeneous transformation matrix (3 x 4)
- (setq aH (append a '(1.0))) ; aH = homogeneous point in local coordinates (1 x 4)
- (setq transpt
- (list
- (+ ; transpt = list of x, y, z coordinates
- (* (nth 0 aH) (nth 0 (nth 0 HTM)))
- (* (nth 1 aH) (nth 0 (nth 1 HTM)))
- (* (nth 2 aH) (nth 0 (nth 2 HTM)))
- (* (nth 3 aH) (nth 0 (nth 3 HTM)))
- )
- (+
- (* (nth 0 aH) (nth 1 (nth 0 HTM)))
- (* (nth 1 aH) (nth 1 (nth 1 HTM)))
- (* (nth 2 aH) (nth 1 (nth 2 HTM)))
- (* (nth 3 aH) (nth 1 (nth 3 HTM)))
- )
- (+
- (* (nth 0 aH) (nth 2 (nth 0 HTM)))
- (* (nth 1 aH) (nth 2 (nth 1 HTM)))
- (* (nth 2 aH) (nth 2 (nth 2 HTM)))
- (* (nth 3 aH) (nth 2 (nth 3 HTM)))
- )
- )
- )
- (setq transpt (list (nth 0 transpt) (nth 1 transpt) (nth 2 transpt)))
- ) ;end transform
可能有一种方法可以使用trans函数来实现这一点。
LRM公司 |