Jump to content

Rapidly rotating three-dimensional solid


highflybird

Recommended Posts

  • Replies 30
  • Created
  • Last Reply

Top Posters In This Topic

  • highflybird

    8

  • marko_ribar

    5

  • GP_

    4

  • steven-g

    4

Top Posters In This Topic

Posted Images

OK a bit rough round the edges as they say, but here is my starter for 10 (which program was that), a macro, I'm LT so I used object to align the UCS in the first part, I believe that swapping that to "face" is an option for solids.

^C^C^Cucs;object;\select;\_copybase;\delete;ucs;view;_pasteclip;0,0;

Link to comment
Share on other sites

Look, Highflybird... I don't know what do you want to achieve... You can use ALIGN command to align 3DSOLID to desired plane and then set view to match aligned surface, and then if you wish just use standard FLATSHOT command to grab it's elevation view... Otherwise I don't know what do you want; with FLATSHOT command you can easily grab any kind of 3D view - and PERSPECTIVE if you wish... For generic axonometry you have to find alternative:

 

Look here :

http://www.theswamp.org/index.php?topic=41965.msg470794#msg470794

 

If you want just to preview 3DSOLID entity, you can use something like this :

;; TRP
;; Transposes a matrix -Doug Wilson-
;;
;; Argument : a matrix

(defun trp (m) (apply 'mapcar (cons 'list m)))

;; MXV
;; Applies a transformation matrix to a vector -Vladimir Nesterovsky-
;;
;; Arguments : a matrix and a vector

(defun mxv (m v)
 (mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)
)

;; MXM
;; Multiplies (combinates) two matrices -Vladimir Nesterovsky-
;;
;; Arguments : two matrices

(defun mxm (m q)
 (mapcar (function (lambda (r) (mxv (trp q) r))) m)
)

;; Unit Vector - Marko Ribar, d.i.a.
;; Args: v - vector in R^n

(defun unit ( v / dst )
 (setq dst (distance '(0.0 0.0 0.0) v))
 (mapcar '(lambda ( x ) (/ x dst)) v)
)

;; Vector Cross Product - Lee Mac
;; Args: u,v - vectors in R^3

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

; transptucs by M.R. (Marko Ribar, d.i.a.)
; arguments : 
; pt - point to be transformed from WCS to imaginary UCS
; pt1 - origin of imaginary UCS
; pt2 - point to define X axis of imaginary UCS (vector pt1-pt2 represents X axis)
; pt3 - point to define Y axis of imaginary UCS (vector pt1-pt3 represents Y axis)
; important note : angle between X and Y axises of imaginary UCS must always be 90 degree for correct transformation calculation

(defun transptucs ( pt p1 p2 p3 / ux uy uz )
 (setq uz (unit (v^v (mapcar '- p2 p1) (mapcar '- p3 p1))))
 (setq ux (unit (mapcar '- p2 p1)))
 (setq uy (unit (mapcar '- p3 p1)))
 
 (mxv (list ux uy uz) (mapcar '- pt p1))
)

; inverse matrix by M.R. (Marko Ribar, d.i.a.)
; arguments : 
; 4x4 transform matrix :
; ((Xx  Yx  Zx  X)
;  (Xy  Yy  Zy  Y)
;  (Xz  Yz  Zz  Z)
;  (0.0 0.0 0.0 1.0))

(defun invmatrix ( 4x4matrix / Xx Xy Xz Yx Yy Yz Zx Zy Zz X Y Z Xinv Yinv Zinv XYZinv invmatrix )
 (setq Xx (car (car 4x4matrix)))
 (setq Xy (car (cadr 4x4matrix)))
 (setq Xz (car (caddr 4x4matrix)))
 (setq Yx (cadr (car 4x4matrix)))
 (setq Yy (cadr (cadr 4x4matrix)))
 (setq Yz (cadr (caddr 4x4matrix)))
 (setq Zx (caddr (car 4x4matrix)))
 (setq Zy (caddr (cadr 4x4matix)))
 (setq Zz (caddr (caddr 4x4matrix)))
 (setq X (cadddr (car 4x4matrix)))
 (setq Y (cadddr (cadr 4x4matrix)))
 (setq Z (cadddr (caddr 4x4matrix)))
 (setq Xinv (transptucs '(1.0 0.0 0.0) '(0.0 0.0 0.0) (list Xx Xy Xz) (list Yx Yy Yz)))
 (setq Yinv (transptucs '(0.0 1.0 0.0) '(0.0 0.0 0.0) (list Xx Xy Xz) (list Yx Yy Yz)))
 (setq Zinv (transptucs '(0.0 0.0 1.0) '(0.0 0.0 0.0) (list Xx Xy Xz) (list Yx Yy Yz)))
 (setq XYZinv (transptucs (list X Y Z) '(0.0 0.0 0.0) (list Xx Xy Xz) (list Yx Yy Yz)))
 (setq invmatrix (list 
                   (list (car Xinv) (car Yinv) (car Zinv) (- (car XYZinv))) 
                   (list (cadr Xinv) (cadr Yinv) (cadr Zinv) (- (cadr XYZinv)))
                   (list (caddr Xinv) (caddr Yinv) (caddr Zinv) (- (caddr XYZinv)))
                   (list 0.0 0.0 0.0 1.0)
                 )
 )
 invmatrix
)

(defun c:objpreview ( / a cent ch d gr loop matrix matrixi obj pt rm vs vsmaxr vsminr xdir xdirxy xdirz ydir ydirxy ydirz zdir )
 (vl-load-com)
 (prompt "\nPick 3DSOLID to preview")
 (vl-cmdf "_.UCS" "w")
 (setq obj (vlax-ename->vla-object (ssname (ssget "_+.:E:S:L" '((0 . "3DSOLID"))) 0)))
 (setq cent (vlax-safearray->list (vlax-variant-value (vla-get-Centroid obj))))
 (vl-cmdf "_.UCS" "m" cent)
 (vla-move obj (vlax-3d-point cent) (vlax-3d-point '(0.0 0.0 0.0)))
 (setq rm (getvar 'regenmode))
 (setvar 'regenmode 0)
 (setq vs (getvar 'viewsize))
 (setq vsmaxr (/ vs 2.0))
 (setq vsminr (/ vs 4.0))
 (setq loop T)
 (prompt "\nLeft click with mouse to change X/Y axis preview rotation or right click with mouse to exit")
 (while loop
   (setq gr (grread T 15 0))
   (setq pt (cadr gr))
   (if (eq (type pt) 'list) (setq d (distance '(0.0 0.0 0.0) pt)))
   (if (<= vsminr d vsmaxr) (setq a (/ (* PI 2.0) (/ (- vsmaxr vsminr) (- vsmaxr d)))) (setq a 0.0))
   (cond 
     ( (eq (car gr) 5) 
       (if ch
         (progn
           (setq xdir (unit pt))
           (setq ydirxy (polar '(0.0 0.0 0.0) (+ (angle '(0.0 0.0 0.0) pt) (/ PI 2.0)) (cos a)))
           (setq ydirz (sin a))
           (setq ydir (list (car ydirxy) (cadr ydirxy) ydirz))
           (setq zdir (unit (v^v xdir ydir)))
           (setq matrix (list (list (car xdir) (car ydir) (car zdir) (car cent)) (list (cadr xdir) (cadr ydir) (cadr zdir) (cadr cent)) (list (caddr xdir) (caddr ydir) (caddr zdir) (caddr cent)) (list 0.0 0.0 0.0 1.0)))
           (if (not matrixi) (vla-transformby obj (vlax-tmatrix matrix)) (vla-transformby obj (vlax-tmatrix (mxm matrix matrixi))))
           (setq matrixi (invmatrix matrix))
         )
         (progn
           (setq xdirxy (polar '(0.0 0.0 0.0) (angle '(0.0 0.0 0.0) pt) (cos a)))
           (setq xdirz (sin a))
           (setq xdir (list (car xdirxy) (cadr xdirxy) xdirz))
           (setq ydir (polar '(0.0 0.0 0.0) (+ (angle '(0.0 0.0 0.0) pt) (/ PI 2.0)) 1.0))
           (setq zdir (unit (v^v xdir ydir)))
           (setq matrix (list (list (car xdir) (car ydir) (car zdir) (car cent)) (list (cadr xdir) (cadr ydir) (cadr zdir) (cadr cent)) (list (caddr xdir) (caddr ydir) (caddr zdir) (caddr cent)) (list 0.0 0.0 0.0 1.0)))
           (if (not matrixi) (vla-transformby obj (vlax-tmatrix matrix)) (vla-transformby obj (vlax-tmatrix (mxm matrix matrixi))))
           (setq matrixi (invmatrix matrix))
         )
       )
     )
     ( (eq (car gr) 3) 
       (if (not ch) (setq ch T) (setq ch nil))
     )
     ( (or (eq (car gr) 25) (eq (car gr) 11))
       (vla-transformby obj (vlax-tmatrix matrixi))
       (vla-move obj (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point cent))
       (setq loop nil)
     )
   )
 )
 (setvar 'regenmode rm)
 (vl-cmdf "_.UCS" "p")
 (vl-cmdf "_.UCS" "p")
 (princ)
)

M.R.

Edited by marko_ribar
code changed
Link to comment
Share on other sites

I managed to find an example drawing with a 3D cube and this macro works, I am just not sure wether it keeps the orintation, I needed to adapt the macro slightly to accept the picked face,

^C^C^Cucs;face;\;select;\_copybase;\delete;ucs;view;_pasteclip;0,0;

And that program was University Challenge

Link to comment
Share on other sites

This is a simple 3D solid

1.jpg

 

when use -view _front, Become like this

2.jpg

 

NOW,What I want is such a result

After running commands, and prompted to select a face

3.jpg

After confirmation, the surface will automatically rotate to the front

 

Use -view _front ,is this

4.jpg

Link to comment
Share on other sites

Why I need this function ?

You have helped me to modified zsst.lsp,

The front view is main view,I want to change the main view to another surface5.jpg

Link to comment
Share on other sites

Wouldn't be temporalily 3d rotation or aligning of desired surface solution? Then you just use ZSST.lsp and that's it... After that you can return 3DSOLID back in position it was before...

Link to comment
Share on other sites

For axonometric projections, I suggest you watch these videos :

 

 

and this one...

 

 

Look into more info for useful links...

 

M.R.

Link to comment
Share on other sites

Wouldn't be temporalily 3d rotation or aligning of desired surface solution? Then you just use ZSST.lsp and that's it... After that you can return 3DSOLID back in position it was before...

 

There is no way, can only use “3drotate” ,The "3drotate" more troublesome .

Link to comment
Share on other sites

For axonometric projections, I suggest you watch these videos :

 

 

and this one...

 

 

Look into more info for useful links...

 

M.R.

 

I'M sorry! I can't open this link In our country

Link to comment
Share on other sites

If I understand correctly...

 

 

467.gif

 

 

(defun c:test ( / *error* cmd os 3Dos pf)
   (defun *error* ( msg )
       (command "_.undo" "_end")
       (command "_.undo" "")        
       (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )
   (setq cmd (getvar 'cmdecho))
   (setq os (getvar 'osmode))    
   (setq 3Dos (getvar '3Dosmode))
   (command "_.undo" "_begin")    
   (setvar 'cmdecho 0)    
   (setvar 'osmode 0)      
   (setvar '3Dosmode 64)
   (command "_-view" "_s" "test")
   (command "_-visualstyles" "_c" "_c")
   (if (setq pf (trans (getpoint "\nSelect a face of solid object: ") 1 0))
       (progn
           (command "_ucs" "_face" (trans pf 0 1) "")
           (command "_copybase" (trans pf 0 1) (trans pf 0 1) "")
           (command "_erase" (trans pf 0 1) "")
           (command "ucs" "_p")
           (command "_-view" "_r" "test")
           (command "_-view" "_d" "test")
           (command "_pasteclip" "\\")
       )
   )
   (setvar '3Dosmode 3Dos)
   (setvar 'osmode os)
   (setvar 'cmdecho cmd)
   (command "_.undo" "_end")
   (princ)
)

Edited by GP_
Erased the last line, residue of the testing.
Link to comment
Share on other sites

If I understand correctly...

(command "_ucs" "_face" (trans pf 0 1) "")
           (command "_copybase" (trans pf 0 1) (trans pf 0 1) "")
           (command "_erase" (trans pf 0 1) "")
           (command "ucs" "_p")
           (command "_-view" "_r" "test")
           (command "_-view" "_d" "test")
           (command "_pasteclip" "\\")

 

+1 deja vu, gets my vote

Link to comment
Share on other sites

GP, I would say that you understand perfectly, and that is spectacular!

It has been added to my Startup Suite, and will be used with alarming regularity. Thanks for sharing! :beer:

Edited by Dadgad
Link to comment
Share on other sites

GP, I suggest that you look into (command-s) function witch I would use inside error handler - that's more efficient and correct use...

 

M.R.

Link to comment
Share on other sites

...deja vu...

Yes, here my muse: :)

^C^C^Cucs;object;\select;\_copybase;\delete;ucs;view;_pasteclip;0,0;

 

 

 

 

GP, I would say that you understand perfectly, and that is spectacular!

It has been added to my Startup Suite, and will be used with alarming regularity. Thanks for sharing!

Thank you, Dadgad. :)

 

 

 

Thank you GP ,I'm in travel...use pad,later, I will try,

I await your test.

 

 

 

GP, I suggest that you look into (command-s) function witch I would use inside error handler - that's more efficient and correct use...

Marko, I'm sorry, I did not understand.

You are free to make any changes...

Link to comment
Share on other sites

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...