phuynh Posted February 4, 2022 Posted February 4, 2022 (edited) Hello everyone! In my finding, the location of the view point as show in picture can be compute mathematically only by highlighted triangle. Would you agree? What if other method exist? Let me know, Thanks! Phh AxonoDwg.pdf Added simple Excel calculation by supplying scale ratio Edited February 4, 2022 by phuynh Quote
mhupp Posted February 4, 2022 Posted February 4, 2022 take a look at this. www.lee-mac.com/2dprojection.html Quote
lrm Posted February 4, 2022 Posted February 4, 2022 @phuynh I'm not sure what you are asking but your dimetric projection is wrong. The two angles that are 30° in the isometric projection are equal but not 30° for a dimetric view. A trimetric view is any axonometric projection that doesn't qualify as an isometric or dimetric projection or orthogonal view. There are 8 possible isometric projections. Note, an isometric projection is about 82% as large as an isometric drawing. The viewpoint for an isometric view is any point where the magnitude of its x, y, and z coordinates are equal. The viewpoint for a dimetric view is any point where the magnitude of its x, y, coordinates are equal and the z coordinate may have any value. . Quote
phuynh Posted February 4, 2022 Author Posted February 4, 2022 Thank you for input, In my understanding, as long as the 2 axis having the same scale ratio and the other 1 is not, then the view is classcify as dimetric, in this case the inclination angles have notthing to do with. Quote
phuynh Posted February 4, 2022 Author Posted February 4, 2022 (edited) In example below using inclination angle to compute location on view point AxonoDwg2.pdf Edited February 4, 2022 by phuynh Quote
phuynh Posted February 4, 2022 Author Posted February 4, 2022 47 minutes ago, lrm said: @phuynh I'm not sure what you are asking but your dimetric projection is wrong. The two angles that are 30° in the isometric projection are equal but not 30° for a dimetric view. A trimetric view is any axonometric projection that doesn't qualify as an isometric or dimetric projection or orthogonal view. There are 8 possible isometric projections. Note, an isometric projection is about 82% as large as an isometric drawing. The viewpoint for an isometric view is any point where the magnitude of its x, y, and z coordinates are equal. The viewpoint for a dimetric view is any point where the magnitude of its x, y, coordinates are equal and the z coordinate may have any value. . It should be dimetric given that the 2 angle of the 2 axis are the same. Quote
phuynh Posted February 21, 2022 Author Posted February 21, 2022 (edited) Information to anyone still interest in this subject: The formulas are available in the internet, by search for term "axonometric calculator" You will come to the page by author name Dave Barber with list all formula and variables how to compute, so credit to the author for his brilliant info's Due to copyright reason, I will not list formula here, but you can easily recreate the calculation by using Excel as you see I list above. You can validate and cross check with his result. My quest is how to apply and use on AutoCAD, and I discover that I can use triangle to compute 3D coordinate that I post here! Phh Updated, noted that Vars "La", "Ca" & "Ra" added for calculate position in AutoCAD Explanation of vars. La, Ca , Ra Calculate highlighted 2D triangle (note all angle are all in Radians) intermediate var La (angle opposite to left inclination or X inclination) La = 90° - Ri = (PI()/2) - Ri intermediate var Ra (angle opposite to right inclination or Y inclination) Ra = 90° - Li = (PI()/2) - Li intermediate var Ca (since known the others 2 angles simply subtract them) Ca = 180° - (La + Ra) = PI() - (La + Ra) At this point all 3 angles are known, then using Sine Rule finding side length For left inclination =(Lr/SIN(La)) * (SIN(La)) For Center inclination =(Lr/SIN(La)) * (SIN(Ca)) For Right inclination =(Lr/SIN(La)) * (SIN(Ra)) 2D length of triangles are known, to convert to 3D coordinate simply divide 2D length to corresponding scale ratio for X coordinate value (corresponding to left inclination) / Lr for Y coordinate value (corresponding to center inclination) / Cr for Z coordinate value (corresponding to right inclination) / Rr phh Edited February 22, 2022 by phuynh Explanation of vars. La, Ca , Ra Quote
marko_ribar Posted February 21, 2022 Posted February 21, 2022 I was doing some researching long time ago... There are some of my videos on YouTube and perhaps some of my codes on www if you search deeper... Here is one : http://www.theswamp.org/index.php?topic=41965 Quote
phuynh Posted February 21, 2022 Author Posted February 21, 2022 (edited) 21 minutes ago, marko_ribar said: I was doing some researching long time ago... There are some of my videos on YouTube and perhaps some of my codes on www if you search deeper... Here is one : http://www.theswamp.org/index.php?topic=41965 Thank you for the information, I also struggle for sometime and how to use it in AutoCAD. Since now I can compute any scale ratios or incline angles, my next step will be writing code in lisp. Cheer! Edited February 21, 2022 by phuynh Quote
phuynh Posted February 22, 2022 Author Posted February 22, 2022 Update, added explanation of vars. La, Ca , Ra, see old post above Phh Quote
marko_ribar Posted February 22, 2022 Posted February 22, 2022 Look, I'll explain a few words of comfort... You can go and experiment as much as you want - all you can find are formulas for transformation coordinates of points of real WCS coordinate system to oblique coodrinate system defining axonometric view... But, please take a look at this note : Quote (vla-transformby) function always performs transformation from WCS (0.0 0.0 0.0) origin : (setq e (car (entsel))) scaling... (vla-transformby (vlax-ename->vla-object e) (vlax-tmatrix (list (list 2.0 0.0 0.0 0.0) (list 0.0 2.0 0.0 0.0) (list 0.0 0.0 2.0 0.0) (list 0.0 0.0 0.0 1.0)))) (vla-transformby (vlax-ename->vla-object e) (vlax-tmatrix (list (list 0.5 0.0 0.0 0.0) (list 0.0 0.5 0.0 0.0) (list 0.0 0.0 0.5 0.0) (list 0.0 0.0 0.0 1.0)))) rotation... (vla-transformby (vlax-ename->vla-object e) (vlax-tmatrix (list (list (cos (cvunit 30 "degree" "radian")) (- (sin (cvunit 30 "degree" "radian"))) 0.0 0.0) (list (sin (cvunit 30 "degree" "radian")) (cos (cvunit 30 "degree" "radian")) 0.0 0.0) (list 0.0 0.0 1.0 0.0) (list 0.0 0.0 0.0 1.0)))) (vla-transformby (vlax-ename->vla-object e) (vlax-tmatrix (list (list (cos (cvunit -30 "degree" "radian")) (- (sin (cvunit -30 "degree" "radian"))) 0.0 0.0) (list (sin (cvunit -30 "degree" "radian")) (cos (cvunit -30 "degree" "radian")) 0.0 0.0) (list 0.0 0.0 1.0 0.0) (list 0.0 0.0 0.0 1.0)))) (transformby with block entity types) you can change blocks non uniform scale factors along X, Y, Z axises which are always mutally orthogonal and yes you can apply tranformation matrix representing mutally orthogonal transformation, but you can't apply transformation matrix representing oblique coordinate system transformation... So if you want to understand difficulty that arises by nature of 3D to 3D trasformation and visual presentation of axonometric view/projection, please accept important facts related to my research I carried in past... To write something useful related to presentation of 3D model geometry, or generally speaking Drawing (DWG), furthest you can go, is to do some conversion of 3D solid stuctures to 3D meshes and then apply transformation formulas to coordinates of their vertices... To spare you valuable time, you'd spend in coding and loosing nerves trying to solve this pretty difficult tasks related to obilique transformations, like I stated, I wrote/coded some examples that are using/(supposed to be using) projecting 3D geometry by using (grread) mouse tracking function in combination with (while) loop-ings to simulate visual effect very much similar to 3D orbiting in currently active "Model" space/layout... I don't know if they are useful to you, or anyone else, but I'll attach them for study/research (if nothing else)... HTH. Regrads, M.R. AXONOMETRY-MONOMETRY-LSP-ROUTINES-MR.ZIP Quote
phuynh Posted February 22, 2022 Author Posted February 22, 2022 (edited) Marko, First, I would like to appreciate your point, the whole subject of axonometry projection will be vast and difficult to take on without research carefully. But here the post as you see on the title, I just indicate that what finding is a way to obtain “ 3D viewpoint on AutoCAD” can be compute and what I am represent here and what I ask for if there is other way to do it. I consider myself as not an expert, learning few tips here & there to complete my goal to make living, finding answer for what I seek, your help and advice always appreciated. I believe within confine of my post with some variables seem unclear, so I continue to update as I re-read my posts, that all. Regarding, the source of the formula I clearly state that something to do with copyright, so I try to point out where I got them. Anyway, I will take your advice seriously, will have your code, do some study, probably couple of year then when I completely understood, then that time will restart conversation. Chao! Phh Edited February 23, 2022 by phuynh Quote
marko_ribar Posted February 23, 2022 Posted February 23, 2022 Look, I took my fre time to revise one of the codes from ZIP I posted... I took, for me the most important one for understanding... BricsCAD is stuggling to operate and AutoCAD can't even start the process... Monometry : The problem is, like I explained : you have rotational X and Y axis, but Z axis is the one that should always be 90 degree viewed from top - actual position of Y axis from WCS... You can get transformation coordinates of points, but it should also be satisfied condition : X scale factor = Y scale factor = 1.0, but Z scale factor = (sqrt 2.0); Rotation is vary (mouse movement);;; Z axis of actual WCS system, should become Z axis of oblique system, where new Z axis is in slope 45 degree to XY plane, so X, Y are the same (rotating, or not), but Z axis is like you twisted it around X of WCS for -45 degree, so imaginary projection - top view (Z is viewed like point), becomes very visible also - top view (Z is viewed like a vertical XLINE overlapping with Y axis)... But like you've figured out, you can not twist Z axis aound X axis just for fun... The problem goes : How to stretch complete DWG so that all entities with height (elevation dimensions) are modified in a way that higher parts (greater elevation) are moved/stretched for their height (delta Z) in Y direction... Those kind of operations simply aren't available, AFAIK... There are stretching parameters for dynamic blocks, but they operate on very basic level with curve entity types... I don't know, maybe someone enlighten me and show me I am wrong... So here is revision, but just for study and nothing else : ;| (vla-transformby) function always performs transformation from WCS (0.0 0.0 0.0) origin : (setq e (car (entsel))) scaling... (vla-transformby (vlax-ename->vla-object e) (vlax-tmatrix (list (list 2.0 0.0 0.0 0.0) (list 0.0 2.0 0.0 0.0) (list 0.0 0.0 2.0 0.0) (list 0.0 0.0 0.0 1.0)))) (vla-transformby (vlax-ename->vla-object e) (vlax-tmatrix (list (list 0.5 0.0 0.0 0.0) (list 0.0 0.5 0.0 0.0) (list 0.0 0.0 0.5 0.0) (list 0.0 0.0 0.0 1.0)))) rotation... (vla-transformby (vlax-ename->vla-object e) (vlax-tmatrix (list (list (cos (cvunit 30 "degree" "radian")) (- (sin (cvunit 30 "degree" "radian"))) 0.0 0.0) (list (sin (cvunit 30 "degree" "radian")) (cos (cvunit 30 "degree" "radian")) 0.0 0.0) (list 0.0 0.0 1.0 0.0) (list 0.0 0.0 0.0 1.0)))) (vla-transformby (vlax-ename->vla-object e) (vlax-tmatrix (list (list (cos (cvunit -30 "degree" "radian")) (- (sin (cvunit -30 "degree" "radian"))) 0.0 0.0) (list (sin (cvunit -30 "degree" "radian")) (cos (cvunit -30 "degree" "radian")) 0.0 0.0) (list 0.0 0.0 1.0 0.0) (list 0.0 0.0 0.0 1.0)))) (transformby with block entity types) you can change blocks non uniform scale factors along X, Y, Z axises which are always mutally orthogonal and yes you can apply tranformation matrix representing mutally orthogonal transformation, but you can't apply transformation matrix representing oblique coordinate system transformation... |; (defun c:monometric-3dorbit ( / *error* unit acos asin all->block viewpredef viewset cmde ucsf ss obj enx p r g q x y f ff v vv ) (vl-load-com) (defun *error* ( m ) (if obj (progn (command-s "_.UNISOLATEOBJECTS") (vla-delete obj) (vl-catch-all-apply 'vlax-release-object (list obj)) (command-s "_.PURGE" "_B" "_MODEL" "_Y" "_Y") ) ) (if ss (command-s "_.ISOLATEOBJECTS" ss "") ) (if ucsf (command-s "_.UCS" "_P") ) (if (= 8 (logand 8 (getvar 'undoctl))) (command-s "_.UNDO" "_E") ) (if cmde (setvar 'cmdecho cmde) ) (if m (prompt m) ) (princ) ) (defun unit ( v / d ) (if (and v (not (equal (setq d (distance '(0.0 0.0 0.0) v)) 0.0 1e-8))) (mapcar '(lambda ( x ) (/ x d)) v) ) ) (defun acos ( x ) (cond ( (equal x 1.0 1e-8) 0.0 ) ( (equal x -1.0 1e-8) pi ) ( (and (not (minusp x)) (equal x 0.0 1e-8)) (/ pi 2) ) ( (and (minusp x) (equal x 0.0 1e-8)) (* 1.5 pi) ) ( (atan (sqrt (- 1.0 (* x x))) x) ) ) ) (defun asin ( x ) (cond ( (equal x 1.0 1e-8) (/ pi 2) ) ( (equal x -1.0 1e-8) (* 1.5 pi) ) ( (and (not (minusp x)) (equal x 0.0 1e-8)) 0.0 ) ( (and (minusp x) (equal x 0.0 1e-8)) pi ) ( (atan x (sqrt (- 1.0 (* x x)))) ) ) ) (defun all->block ( name pt ss adoc / s l b ) ;;; return VLA-OBJECT ("INSERT") representing complete DWG from perspective of what was/is curretly visible in active/current space/layout... (if (and ss (= (type ss) 'pickset) (/= (sslength ss) 0) pt (= (type pt) 'list) (= (length pt) 3)) (progn (vlax-for o (setq s (vla-get-activeselectionset adoc)) (setq l (cons o l)) ) (vla-delete s) (vlax-invoke adoc 'copyobjects l (setq b (vlax-invoke (vla-get-blocks adoc) 'add (vlax-3d-point (trans pt 1 0)) name))) (vla-insertblock (vla-get-block (vla-get-activelayout adoc)) (vlax-3d-point (trans pt 1 0)) name 1.0 1.0 1.0 0.0) ) ) ) ;; ViewsNoZoom.lsp ;; For changing to Predefined View directions (in World Coordinates), such as those in ;; AutoCAD's "Views" Toolbar, BUT with the center of the view and the magnification ;; remaining as they are, WITHOUT Zooming out to the drawing extents as AutoCAD's ;; icons do. Uses DVIEW and its Points option, not the AutoCAD icons' VIEW approach, ;; or VPOINT. Also includes Isometric Views from the BELOW-the-equator points of ;; view (not available among AutoCAD's pre-defined icons). ;; Uses abbreviations for compass directions for Orthogonal as well as Isometric views, ;; and "Overhead" & "Underneath" in place of "Top" & "Bottom" or "Above" & "Below", ;; to make it easier to remember for typing in, avoiding potential uncertainty for some ;; directions, e.g. R could be for Right or Rear, B could be for Back, Below or Bottom. ;; ;; Kent Cooper, June 2009 (defun viewpredef ( dir pp / cmde vc ucsff ) (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0) (if pp (setq pp (trans pp 1 0)) (setq vc (trans (getvar 'viewctr) 1 0)) ) (if (= 0 (getvar 'worlducs)) (progn (vl-cmdf "_.UCS" "_W") (setq ucsff t) ) ) (if pp (vl-cmdf "_.DVIEW" "" "_POINTS" "_non" pp "_non" dir "") (vl-cmdf "_.DVIEW" "" "_POINTS" "_non" vc "_non" dir "") ) (if ucsff (vl-cmdf "_.UCS" "_P") ) (setvar 'cmdecho cmde) (princ) ); end defun (defun viewset ( pp / dir ); = View: Orthogonal from Overhead (setq dir (trans (list 0.0 0.0 1.0) 1 0 t)) (viewpredef (strcat "@" (rtos (car dir) 2 50) "," (rtos (cadr dir) 2 50) "," (rtos (caddr dir) 2 50)) pp) ); end defun (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0) (if (= 8 (logand 8 (getvar 'undoctl))) (vl-cmdf "_.UNDO" "_E") ) (vl-cmdf "_.UNDO" "_G") (if (= 0 (getvar 'wolrducs)) (progn (vl-cmdf "_.UCS" "_W") (setq ucsf t) ) ) (viewset (setq p (getvar 'viewctr))) (setq ss (ssget "_A" (list '(0 . "~VIEWPORT") '(60 . 0) (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model"))))) (if (and (setq obj (all->block "_MODEL" p ss adoc)) (setq enx (entget (vlax-vla-object->ename obj)))) (progn (vl-cmdf "_.ISOLATEOBJECTS" (vlax-vla-object->ename obj) "") (setq p (trans p 1 2)) (setq r (/ (cadr (getvar 'screensize)) 2.0)) (while (= (car (setq g (grread t))) 5) (if (and (= (type (setq q (cadr g))) 'list) (= (length q) 3)) (progn (setq q (trans q 1 2)) (if (not (equal p q 1e-15)) (progn (setq x (- (car q) (car p))) (setq y (- (cadr q) (cadr p))) (if (and (not (equal x 0.0 1e-8)) (not (equal y 0.0 1e-8))) (progn (if (not f) (setq f (lambda ( u ) (list (* (cos (+ (atan (cadr u) (car u)) (if (or (> (sin (atan y x)) 0.999) (< (sin (atan y x)) -0.999)) (atan y x) 0.0) (/ pi 4))) (distance '(0.0 0.0) u)) (+ (* (sin (+ (atan (cadr u) (car u)) (if (or (> (sin (atan y x)) 0.999) (< (sin (atan y x)) -0.999)) (atan y x) 0.0) (/ pi 4))) (distance '(0.0 0.0) u)) (caddr u)) (caddr u)))) ;;; transformation function : 3D WCS point - top projection => 3D WCS point - monometric projection ) (if (not ff) (setq ff (lambda ( u ) ( (lambda ( q / d a aa ) (setq d (distance '(0.0 0.0) (list (car u) (- q (caddr u))))) (setq a (asin (/ (- q (caddr u)) d))) (setq aa (if (or (> (sin (atan y x)) 0.999) (< (sin (atan y x)) -0.999)) (- a (/ pi 4)) (- a (atan y x) (/ pi 4)))) (list (if (equal (atan (- q (caddr u)) (car u)) (+ aa (/ pi 4) (if (or (> (sin (atan y x)) 0.999) (< (sin (atan y x)) -0.999)) (atan y x) 0.0)) 1e-6) (* (cos aa) d) (* (sin aa) d)) (if (equal (atan (- q (caddr u)) (car u)) (+ aa (/ pi 4) (if (or (> (sin (atan y x)) 0.999) (< (sin (atan y x)) -0.999)) (atan y x) 0.0)) 1e-6) (* (sin aa) d) (* (cos aa) d)) (caddr u))) (cadr u) ))) ) ;;; inverse function from function f : 3D WCS point - monometric => 3D WCS point - top projection (setq v (list (* (cos (+ (atan y x) (/ pi 4))) (sqrt 2.0)) (* (sin (+ (atan y x) (/ pi 4))) (sqrt 2.0)) 1.0)) ;;; vector V - fictional vector whose components represent coordinates in WCS top projection dependable from rotational angle - (grread) mouse movement [ (atan y x) ] ; for angle 0.0 => V = (1.0 1.0 1.0) ; for angle 90 degree => V = (-1.0 1.0 1.0) ; for angle 180.0 degree => V = (-1.0 -1.0 1.0) ; for angle 270.0 degree => V = (1.0 -1.0 1.0) ; for angle 360.0 degree => V = (1.0 1.0 1.0) (setq vv (f v)) ;;; vector VV - fictional vector whose components represent coordinates of transormed vector V in monometric projection dependable from rotational angle - (grread) mouse movement [ (atan y x) ] ; for angle 0.0 => VV = (0.0 2.41421356237309 1.0) ; for angle 90 degree => VV = (-1.4142135623731 1.0 1.0) ; for angle 180.0 degree => VV = (0.0 -0.414213562373095 1.0) ; for angle 270.0 degree => VV = (1.4142135623731 1.0 1.0) ; for angle 360.0 degree => VV = (0.0 2.41421356237309 1.0) (setq enx (mapcar '(lambda ( q ) (cond ( (= (car q) 41) (cons 41 (car vv)) ) ( (= (car q) 42) (cons 42 (cadr vv)) ) ( (= (car q) 43) (cons 43 (caddr vv)) ) ( (= (car q) 50) (cons 50 (+ (atan y x) (/ pi 4))) ) ( t q ))) enx)) (prompt (strcat "\n\tV = (" (rtos (car v) 2 8) " " (rtos (cadr v) 2 8) " " (rtos (caddr v) 2 8) ")\tVV = (" (rtos (car vv) 2 8) " " (rtos (cadr vv) 2 8) " " (rtos (caddr vv) 2 8) ")\tRotation Angle of vector V = " (rtos (cvunit (rem (+ (atan y x) (/ pi 4)) (* 2 pi)) "radian" "degree") 2 8) " degrees \tAngle (mouse movement) = " (rtos (cvunit (rem (atan y x) (* 2 pi)) "radian" "degree") 2 8))) (entupd (cdr (assoc -1 (entmod enx)))) (gc) ) ) ) ) ) ) ) ) (prompt "\nNo visible objects in active/current space/layout... Draw something firstly and then restart routine...") ) (*error* nil) ) Quote
phuynh Posted February 23, 2022 Author Posted February 23, 2022 Explaining how I am getting here, Here I go, About 10 years ago, One day my boss came, and he said, our company have about 200 solid model parts that we want you to produce 2D drawing’s isometric view for marketing and send to client with the following parameters left inclination 10 degrees, right inclination 40 degrees (or X scale 1.0, Z scale at 1.0 and Y scale 2/3) etc. Yes boss, that easy as I though! At first, I try AutoCAD isometric, but this view only produces inclination angle of 30, 30 and it not falling in with the specification requirement 10, 40. At this point I think yeh, I may do some quick eyeballing to get 10, 40 inclinations and at same time I realize that there must be a better way that setting up the viewpoint so that when I do “flatshot” it can re-produce 10, 40 inclinations, but how. I set out to forum look for information of this type, but I come up empty. In my quest of looking answer, most of info’s explaining type of axonometric projection and so for but hardly explaining how to get viewpoint. So, my point here is how to get viewpoint in AutoCAD that can predictably & consistently when I know either inclination angles or scale ratios of XYZ A-axis, Of course, trial & error part of process, I use Excel to compute, create some AutoCAD command so I can test them out quickly by copy & paste. My intention to post in this forum is what I try validating my finding, I also asking if any better way to get the result. I accept all your opinion, teaching and always appreciated, Please spare me for my bad English, I hope I learn a thing or two! Thanks!, Phh Quote
lrm Posted March 2, 2022 Posted March 2, 2022 (edited) @phyunh First off, I agree that the view in your first post is a dimetric view. What threw me off was that in a typical dimetric view the axis of symmetry is vertical. In your dimetric view you have set the axis of symmetry to 38.5802 degrees. It’s not clear why. To create an axonometric projection in AutoCAD you can either move you (the observer) by changing the viewpoint or by rotating the 3D object in 3D space. If you rotate the object the axonometric projection can be seen in a principal view. Typically the front view. Let’s look at the “rotating the object” method. The following assumes we are looking at the front of an object in the AutoCAD front view and therefore viewing the object perpendicular to the world XZ plane. To rotate an object to an isometric orientation you can first rotate it (using rotate3d) by + or - 45 degrees about the Z axis and then 35.2644 degrees about the x axis. The angle 35.2644 is the angle that a diagonal of a unit cube makes with its base, the arctangent of (1/ sqrt(2)). To rotate an object to a dimetric orientation the first rotation is also 45 degrees about Z but then any angle (except +/- 35.2644) about the x axis. This second rotation tilts the object up or down but maintains a dimetric projection. The dimetric view you posted would require a third rotation about the world z axis to change the slope of the axis of symmetry from the vertical default to another angle (e.g., 38.5802). A trimetric view with pre-specified angles of inclination for the two non-vertical axes can be created in a similar fashion if the two angle of rotation are known. It’s no simple task to determine these angles as you have noted! I found the task intriguing so to help determine these angles I created the attached Excel file Trimetric View Calculator.xlsx. To help me debug the spreadsheet I included many intermediates calculation values on the sheet including rotation matrices and computed points I could compare with AutoCAD values. To use the spreadsheet the user enters values for the rotations about the Z and X axis. The resulting orientation of the right and left inclination axes are determined as well as the coordinates of a view point. The two angles can be used to rotate the object yielding the corresponding axonometric orientation when view from the world front view. If you do not want to rotate the object you can use the view point coordinates to yield the identical axonometric projection. As an example let’s assume that we would like to create the trimetric view you used with a left inclination of 10° and a right inclination 40°. There are two angles for rotating the object in 3D that we need to determine. The first is the angle of rotation about the world Z axis while the second rotation angle is about the world x axis. In the following example setting Z to 45 and X to 35.2644 we see that the angle of inclination for the two axes is 30°. That is, an isometric view. The Excel file also computes a viewpoint that would yield the same axonometric projection (-0.5744, -.5744, 0.5774). Obviously, this would yields the same isometric view as using a view point of (-1,-1,1). The Excel file does not bother to scale the view point but leaves it as a unit vector. With this worksheet it requires a bit of trial and error to determine the two rotation angles (or a viewpoint) that would create the 40° right axis and 10° left axis. For example, a guess of 50 for the Z rotation and 20 for the X rotation yields 22.176 and 16.013 respectively. A few more guesses adjusted by the results of previous guesses yields and angle of 65° for the Z rotation and 23° for the X rotation resulting in a trimetric projection with the right axis at 39.961° and the left axis at 10.326° (see below). This may be close enough for a pictorial drawing. If you prefer to use a viewpoint then it is available too (-0.8343, -0.3890, 0.3907). This assumes a base point of (0, 0, 0). To make this process more automatic and remove the guesswork I wrote an Excel/VBA program to cycle through combinations of the two angles to search for an acceptable solution. The file “Trimetric view calculator VBA.xlsm” contains the VBA enhanced version. The program is not elegant as it uses a brute force approach incrementing the X angle from 1 to 359 degrees before incrementing the Z rotation angle. Here are the results where the tolerance was set to 0.1° and the angle increment step size to 0.1°. The compute time was about 15 seconds on my old PC. The result by rotating the object. The result by specifying a view point. Option Explicit Option Base 1 'Trimetric view calculator 'Lee Minardi 3/1/2022 ' Sub main() Dim matrixXrot(3, 3) As Double Dim matrixZrot(3, 3) As Double Dim vectorA(3) As Double Dim vectorB(3) As Double Dim RightAngGoal As Double, LeftAngGoal As Double Dim RightAng As Double, LeftAng As Double Dim RightvZrot, LeftvZrot, RightvXrot, LeftvXrot Dim Tol As Double, AngStep As Double, Pi As Double Dim ZRot As Double, XRot As Double, msg Dim SolnFound As Boolean Dim vpointx, vpointy, vpointz, vpoint Range("A3").Select Pi = 3.14159265358979 RightAngGoal = ActiveCell.Value 'goal for right inclination angle ActiveCell.Offset(1, 0).Select LeftAngGoal = ActiveCell.Value 'goal for left inclination angle ActiveCell.Offset(1, 0).Select AngStep = ActiveCell.Value ActiveCell.Offset(1, 0).Select Tol = ActiveCell.Value SolnFound = False vectorA(1) = 1: vectorA(2) = 0: vectorA(3) = 0: vectorB(1) = 0: vectorB(2) = 1: vectorB(3) = 0: For ZRot = 1 To 359 Step AngStep Call RotMatrix(ZRot, "Z", matrixZrot) RightvZrot = Application.MMult(vectorA, matrixZrot) LeftvZrot = Application.MMult(vectorB, matrixZrot) For XRot = 1 To 359 Step AngStep Call RotMatrix(XRot, "X", matrixXrot) RightvXrot = Application.MMult(RightvZrot, matrixXrot) LeftvXrot = Application.MMult(LeftvZrot, matrixXrot) If RightvXrot(1) <> 0 Then RightAng = Atn(RightvXrot(3) / RightvXrot(1)) Else RightAng = 0# RightAng = RightAng * 180# / Pi If LeftvXrot(1) <> 0 Then LeftAng = Atn(LeftvXrot(3) / LeftvXrot(1)) Else LeftAng = 0# LeftAng = -LeftAng * 180# / Pi If Abs(RightAngGoal - RightAng) < Tol And Abs(LeftAngGoal - LeftAng) < Tol Then SolnFound = True Exit For End If Next XRot If SolnFound Then Exit For Next ZRot If SolnFound Then Range("a10").Select ActiveCell.Value = Round(ZRot, 3) ActiveCell.Offset(0, 2).Select ActiveCell.Value = Round(XRot, 3) Range("a12").Select ActiveCell.Value = Round(RightAng, 4) Range("a14").Select ActiveCell.Value = Round(LeftAng, 4) vpointx = Round(-Sin(Radians(ZRot)) * Cos(Radians(XRot)), 4) vpointy = Round(-Cos(Radians(ZRot)) * Cos(Radians(XRot)), 4) vpointz = Round(Sin(Radians(XRot)), 4) Range("a17").Select ActiveCell.Value = vpointx ActiveCell.Offset(0, 1).Select ActiveCell.Value = vpointy ActiveCell.Offset(0, 1).Select ActiveCell.Value = vpointz Range("a1").Select vpoint = vpointx & ", " & vpointy & ", " & vpointz msg = "Solution Found." & vbCrLf & _ "Z Rotation = " & Round(ZRot, 3) & "° Right axis angle = " & Round(RightAng, 4) & "°" & vbCrLf & _ "X Rotation = " & Round(XRot, 3) & "° Left axis angle = " & Round(LeftAng, 4) & "°" & vbCrLf & vbCrLf _ & "or use" & vbCrLf & _ "View Point: " & vpoint MsgBox msg, vbExclamation Else MsgBox "No solution found. Increase tolerance or " & vbCrLf & "decrease step size.", vbCritical End If End Sub Sub RotMatrix(angle, mRot, m) ' mRot = "X", "Y", or "Z" ' m = resulting matrix from rotation about the mRot axis Dim angleR As Double angleR = angle * 3.14159265358979 / 180# Select Case mRot Case "X" m(1, 1) = 1: m(1, 2) = 0: m(1, 3) = 0 m(2, 1) = 0: m(2, 2) = Cos(angleR): m(2, 3) = Sin(angleR) m(3, 1) = 0: m(3, 2) = -Sin(angleR): m(3, 3) = Cos(angleR) Case "Y" ' not defined Case "Z" m(1, 1) = Cos(angleR): m(1, 2) = Sin(angleR): m(1, 3) = 0 m(2, 1) = -Sin(angleR): m(2, 2) = Cos(angleR): m(2, 3) = 0 m(3, 1) = 0: m(3, 2) = 0: m(3, 3) = 1 End Select End Sub Function Radians(angle) Radians = angle * 3.14159265358979 / 180# End Function Lee Trimetric view calculator.zip Edited March 2, 2022 by lrm Quote
phuynh Posted March 27, 2022 Author Posted March 27, 2022 @lrm, i agree with your method of calculation in general, yes it works with some caveat, for example the precision of angle (or scale ratios), let say within 6 digits it maybe problematic. Phh Quote
phuynh Posted March 27, 2022 Author Posted March 27, 2022 In my opinion, 2 methods of obtaining axonometric viewpoint in AutoCAD programmatically by given inclination angle input or scale ratio input. My use of inclination angle is 1% and scale ratio is 99%. I find myself editing a lot after "flatshot" so the scale ratio is really importance to me, give me the ability to know ahead what I need to do and so for etc. Dave Barber calculation methods and his formulas are best, I did apply & check the accuracy when try his formula to calculating 3D view point, at a minimum 6 decimal digits but it turn out very high 13 or 15 (AutoCAD, Excel)! Also in his calculation the "DR" intermediate variable give me ahead how much I need to scale after "flatshot" to match the drawing unit. Regarding "DR" intermediate variable, it so importance that I end up planing to write separate routine as lisp reactor so it always available in my AutoCAD session. My plan to obtain DR from AutoCAD = DR intermediate variable = function calculates VIEWDIR Did you know that VIEWDIR system variable is actually 3D viewpoint? For me this really fun! brain teasing, feel like going back to school to rediscover what I was missing. Cheer! my 2 cents. Phh Quote
phuynh Posted March 27, 2022 Author Posted March 27, 2022 Shown here are the effect to "DR intermediate variable" in simple 1" cube in AutoCAD "SW Isometric" AutoCAD "FLATSHOT" without any scaling AutoCAD "FLATSHOT" with custom script scaling based on "DR intermediate variable" Just like going back to old school style of manual drafting, 2D drawing!, start out drawing 1 unit length with angle 30 degrees... Phh Quote
phuynh Posted March 27, 2022 Author Posted March 27, 2022 (edited) The effect "DR intermediate variable" in simple 1" cube in AutoCAD with scale ratio input, X-Axis = 1 Z-Axis = 3/4 Y-Axis = 4/5 On the left, with no "DR" scaling, on the right with "DR" scaling, see "(vl-cmdf "_.SCALE" "L" "" "0,0" 1.04940459309077)" and it easy to visualize Phh Edited March 30, 2022 by phuynh Quote
phuynh Posted April 25, 2022 Author Posted April 25, 2022 (edited) "DR intermediate variable" compute using AutoCAD system variable "VIEWDIR" I know it shouldn't be that long, but I tense to keep all notes and comments so I track what I'm doing. The routine compute and return Dr variable value at command prompt based on current "VIEWDIR" Phh ;;----------------------------------------------------------;; ;; Compute "Dr" based on AutoCAD system variable "VIEWDIR" ;; ;; By Phh 4/10/2022 ;; ;;----------------------------------------------------------;; (vl-load-com) (defun c:drc (/ pt0 pt1 ptx pty ptz hxLs hyRs hzCs Lr Rr Cr n Drvar old_cmdecho old_osmode) ;;----------------------------------;; ;; Start error traperr & save vars. ;; ;;----------------------------------;; (setq temperr *error*) (setq *error* traperr) (setq old_cmdecho (getvar "CMDECHO")) (setq old_osmode (getvar "OSMODE")) ;;-----------------;; ;; Setup variables ;; ;;-----------------;; (setq pt0 '(0 0 0)) (setq ptx '(1 0 0)) (setq pty '(0 1 0)) (setq ptz '(0 0 1)) (setq pt1 (getvar "VIEWDIR")) ;;------------------------------------------------------------;; ;; Test if current view point is none orthographic projection ;; ;; then compute Dr, otherwise skip ;; ;;------------------------------------------------------------;; (setq n (apply '+ (mapcar 'abs pt1))) (if (or (> (- n (fix n)) 0) (= n 3.0)) (progn (princ "\nDr variable = ") ;;; ;;********************************************** ;;; ;;--------------------------------------------;; ;;; ;; For visual debug, comment out default ;; ;;; ;;--------------------------------------------;; ;;; (setvar "OSMODE" 0) ;;; (setvar "CMDECHO" 0) ;;; (vl-cmdf "LINE" pt0 pt1 "") ; base of all 3 triangles ;;; (vl-cmdf "LINE" pt0 ptx pt1 "") ; draw a line from ptx perpendicular to the base it should be equal hxLs ;;; (vl-cmdf "LINE" pt0 pty pt1 "") ; draw a line from pty perpendicular to the base it should be equal hyRs ;;; (vl-cmdf "LINE" pt0 ptz pt1 "") ; draw a line from ptz perpendicular to the base it should be equal hzCs ;;; ;;********************************************** ;;-----------------------------------------------;; ;; Calculate height of triangle relative to base ;; ;; (note: base = vector pt0 to pt1) ;; ;; h=2*area/base ;; ;;-----------------------------------------------;; (setq hxLs (/ (* 2 (area3pts (list pt0 pt1 ptx))) (distance pt0 pt1))) (setq hyRs (/ (* 2 (area3pts (list pt0 pt1 pty))) (distance pt0 pt1))) (setq hzCs (/ (* 2 (area3pts (list pt0 pt1 ptz))) (distance pt0 pt1))) ;;---------------------------------;; ;; Calculate scale ratios ;; ;; Note: ;; ;; hxLs equivalent to Ls in Excel ;; ;; hyRs equivalent to Rs in Excel ;; ;; hzCs equivalent to Cs in Excel ;; ;;---------------------------------;; (setq Lr (/ hxLs (max hxLs hyRs hzCs))) (setq Rr (/ hyRs (max hxLs hyRs hzCs))) (setq Cr (/ hzCs (max hxLs hyRs hzCs))) ;; Dr calculate based on Dave Barber's formula (setq Drvar (sqrt (* 0.5 (+ (* Lr Lr) (* Cr Cr) (* Rr Rr))))) ;;-------------------------------------------;; ;; For visual debug, comment out if you want ;; ;; display Drvar 15 digits ;; ;;-------------------------------------------;; (setq Drvar (rtos Drvar 2 15)) (princ Drvar) (princ) (setvar "OSMODE" old_osmode) (setvar "CMDECHO" old_cmdecho) ) ;;----------------------------------------------------;; ;; Orthographic projection, skip calculation ;; ;;----------------------------------------------------;; (progn (princ "\nOrthographic projection, skip calculation") (princ) ) ) ) ;; --------------------------------------------------;; ;; Calculates area of triangle by supplied 3 points ;; ;; Heron's formula: ;; ;; Area=0.25*sqrt((a+b+c)*(-a+b+c)*(a- b+c)*(a+b-c)) ;; ;;---------------------------------------------------;; (defun area3pts (list3pts / a b c theArea) (setq a (distance (car list3pts) (cadr list3pts))) (setq b (distance (car list3pts) (caddr list3pts))) (setq c (distance (cadr list3pts) (caddr list3pts))) (setq theArea (* 0.25 (sqrt (* (+ a b c) (+ (* -1 a) b c) (+ a (* -1 b) c) (+ a b (* -1 c)) ) ) ) ) ) ;;----------------------------------------------;; ;; Error traper function restore save variables ;; ;;----------------------------------------------;; (defun traperr (errmsg) (setvar "CMDECHO" old_cmdecho) (setvar "OSMODE" old_osmode) (setq *error* temperr) (prompt "\Resetting system variables ") (princ) ) Edited April 25, 2022 by phuynh Quote
Recommended Posts
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.