samifox Posted August 1, 2014 Share Posted August 1, 2014 hi i admit, (trans) is one of those scary functions i always ignore learning, it seems too complicated, now its time to deal with it, so let me please layout all i understand so far, trans is all about translating the actual location of a coordinate to any coordinate system available in Autocad. WCS World Coordinate System is actually the world, fixed coordinate system which sponsor all the other systems. UCS on top of the WCS, user can define a new layer of coordinates, with a user defined origin's location and rotation, the relationship with the WCS is maintained by Autocad. OCS Object System Coordinates (trans pt from tp [disp]) Objects wont change their location due to shifting from one coordinates system to another, autocad translate automatically between the systems. For Autolisp programming this automatic translation wont happen, object coded to be drawn in WCS, wont be the same when drawn on UCS with different origin. (trans) is used to make this translation. END OF MIND things i still dont get 1. about OCS, the coordinates retirved by entget suppose to show the relative coordinates to the objects, but they are relative to the WCS, what am i missing? 2. about using a vector rather than a coordinate, can you give example? 3. in one of Mac Lee's code i saw this: enx (entget (ssname sel (1- inc))) spf (polar '(0.0 0.0) (+ (cdr (assoc 50 enx)) (/ pi 2.0)) (* (cdr (assoc 40 enx)) spf)) [color="red"][b]vec (trans spf (trans '(0.0 0.0 1.0) 1 0 t) 0)[/b][/color] can anyone explain this (Including the author:)) Thanks Shay Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted August 2, 2014 Share Posted August 2, 2014 im not good in explanation, its about the rotation of XY plane at axis-z, please advise if i'm wrong thanx In math: (defun shay:Trans? (p bp v / ); p= pt bp=base v=radians (list (+(*(- (car p) (car bp)) (cos v)) (*(- (cadr p) (cadr bp)) (sin v))) (-(*(- (cadr p) (cadr bp)) (cos v)) (*(- (car p) (car bp)) (sin v ))) (caddr p) ) ) Example how it transformed to new coordinates? (104,103,5.0) --> (5.0 0.0 5.0) This is a theory, so can test in WCS (setq base '(100. 100. 0.) ; pt '(104. 103. 5.0)) _$ ( shay:Trans? pt base (angle base pt)); (5.0 4.44089e-016 5.0) _$ Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 2, 2014 Share Posted August 2, 2014 3. in one of Mac Lee's code i saw this: enx (entget (ssname sel (1- inc))) spf (polar '(0.0 0.0) (+ (cdr (assoc 50 enx)) (/ pi 2.0)) (* (cdr (assoc 40 enx)) spf)) [color=red][b]vec (trans spf (trans '(0.0 0.0 1.0) 1 0 t) 0)[/b][/color] can anyone explain this (Including the author:)) See my explanation here: http://www.theswamp.org/index.php?topic=47544.msg525391#msg525391 As for an explanation of trans, there are several to be found - here are a couple: http://www.theswamp.org/index.php?topic=13526.0 http://www.theswamp.org/index.php?topic=31802 Quote Link to comment Share on other sites More sharing options...
samifox Posted August 4, 2014 Author Share Posted August 4, 2014 See my explanation here: http://www.theswamp.org/index.php?topic=47544.msg525391#msg525391 As for an explanation of trans, there are several to be found - here are a couple: http://www.theswamp.org/index.php?topic=13526.0 http://www.theswamp.org/index.php?topic=31802 Thanks Lee since my (trans) episode im working really hard, my brain is burning trying to get a grasp of the subject, ive learned the links you posted, your text align code , and still cant say that i win the subject according to the (trans) documentation example, im tring to draw a line from the insertion point of the text, i've rotated the UCS, i paste a piece of text , and i execute this: (defun txt() (setq ent (entget(car(entsel)))) (setq ip (cdr(assoc 10 ent))) (setq ip (trans ip ent 1)) (command "_line" ip) ) i got this error : ; error: bad argument type: coordinate system specification: ((-1 . <Entity name: 7ffffbaec70>) (0 . "TEXT") (330 . <Entity name: 7ffffb189f0>) (5 . "1BF") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbText") (10 14.9945 10.9974 0.0) (40 . 0.2) (1 . "(command \"_point\" spf)") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0)) whats wrong? Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted August 4, 2014 Share Posted August 4, 2014 try use en not ent (setq [color="red"]en[/color] (car (entsel))) .. .. (trans ip [color="red"]en[/color] 1) Quote Link to comment Share on other sites More sharing options...
samifox Posted August 4, 2014 Author Share Posted August 4, 2014 try use en not ent (setq [color="red"]en[/color] (car (entsel))) .. .. (trans ip [color="red"]en[/color] 1) you think ent is not empty and protected? Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted August 4, 2014 Share Posted August 4, 2014 Nope, your ent is just an entget list, not an ename (car(entsel)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 4, 2014 Share Posted August 4, 2014 hanhphuc is correct - The trans function will accept either an integer corresponding to a coordinate system enumeration (0=WCS, 1=UCS etc.), a normal vector from which a coordinate system will be constructed using the Arbitrary Axis Algorithm, or an entity name (for which the function will use the OCS of the entity). In your code you are supplying an association list of DXF group codes, which is not a valid argument. I would also advise accounting for possible interference with Object Snap: (defun txt ( / ent ) (if (setq ent (car (entsel))) (command "_.line" "_non" (trans (cdr (assoc 10 (entget ent))) ent 1) "\\" "") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
samifox Posted August 5, 2014 Author Share Posted August 5, 2014 (edited) hi (setvar "PDMODE" 34) (setq p 0.0) (setq n 0.0) (defun test1 (/ p n) (setq p (getpoint)) (repeat 5 (setq p (append (list (+ (car p) 10.0)) (list (cadr p)))) (setq p (trans p 0 1)) (command "_.point" "_non" p ) ) ) if i modify the UCS, this code is forming angular points order....why? and...without trans its seems the expected results? confused! ? Edited August 5, 2014 by samifox Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 5, 2014 Share Posted August 5, 2014 getpoint returns points wrt UCS. Quote Link to comment Share on other sites More sharing options...
samifox Posted August 6, 2014 Author Share Posted August 6, 2014 getpoint returns points wrt UCS. so, getpoint translateed the point for me? and how you explain the angular form? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 7, 2014 Share Posted August 7, 2014 so, getpoint translateed the point for me? and how you explain the angular form? No, getpoint returns the user-specified point with respect to the UCS - You are repeatedly transforming this UCS point as if it were a WCS to UCS. As for the apparent rotation of the point: Consider an example in which your UCS is rotated by, say, 23 degrees (an arbitrary value). Now consider that you have used your program to pick the point (1 1) relative to the rotated UCS. The getpoint function will hence return this point as (1 1). Your program then increments the x-value by 10 units, so the point becomes (11 1). Now, you redefine the point using trans, supplying the point (11 1) as if it were a WCS coordinate to be translated relative to the active UCS. In your UCS rotated by 23 degrees, the WCS point (11 1) becomes the UCS point (10.5163 -3.37754 0.0) - a Point object is then constructed at this coordinate. On the next iteration, the program will again increment the x-value of the point by 10 units, however, since you have redefined the value of the variable 'p', this variable now holds the value (20.5163 -3.37754 0.0). And again, this apparent UCS coordinate is supplied as if it were a WCS point to be translated to the UCS, returning the point (17.5656 -11.1254 0.0). This process is repeat 5 times resulting in the curved pattern you have witnessed. This pattern occurs because rather than translating the point by the horizontal vector '(10 0) for each iteration, you are translating it by a vector following the angle of the UCS x-axis relative to the WCS x-axis, causing the point translation to follow a circular path. Quote Link to comment Share on other sites More sharing options...
samifox Posted August 12, 2014 Author Share Posted August 12, 2014 Hi I've opened a case study in order to investigate the subject of coordinate system. would like to get get challenges from the gurus here(basic to advance). my first basic challenge is to adopt a new ucs, and draw a line between the WCS origin to UCS origin. in my code i translate the UCS 0,0,0 coordinate to the WCS but its draw a line which is not as expected.why? help please! ;draw a line from Ucs origin to the WCS origin (defun cs1(/ WCS UCS) ;get WCS orign (setq WCS (trans '(0.0 0.0 0.0)1 0)) ;get UCS origin (setq UCS '(0.0 0.0 0.0)) ;draw line (command "_.line" "_non" WCS UCS "") ) Thanks Shay Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted August 12, 2014 Share Posted August 12, 2014 Hiin my code i translate the UCS 0,0,0 coordinate to the WCS but its draw a line which is not as expected.why? if WCS=UCS, zero line created. unless USC moved or rotated then can see the difference. Quote Link to comment Share on other sites More sharing options...
samifox Posted August 12, 2014 Author Share Posted August 12, 2014 But i test it where ucs unequal wcs Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted August 12, 2014 Share Posted August 12, 2014 i don't really understand "draw a line which is not as expected" nothing drawn? can you show image? Quote Link to comment Share on other sites More sharing options...
samifox Posted August 12, 2014 Author Share Posted August 12, 2014 i don't really understand "draw a line which is not as expected" nothing drawn? can you show image? Hi the lines is drawen , but not where i ment look the visual Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 12, 2014 Share Posted August 12, 2014 Commands use UCS points - you are translating the UCS origin to WCS; use (trans '(0.0 0.0 0.0) 0 1) Alternatively: (defun cs2 nil (entmake (list '(0 . "LINE") '(10 0.0 0.0 0.0) ;; WCS origin (cons 11 (trans '(0.0 0.0 0.0) 1 0)) ;; UCS origin ) ) ) Quote Link to comment Share on other sites More sharing options...
samifox Posted August 12, 2014 Author Share Posted August 12, 2014 Commands use UCS points - you are translating the UCS origin to WCS; use (trans '(0.0 0.0 0.0) 0 1) Alternatively: (defun cs2 nil (entmake (list '(0 . "LINE") '(10 0.0 0.0 0.0) ;; WCS origin (cons 11 (trans '(0.0 0.0 0.0) 1 0)) ;; UCS origin ) ) ) Hi Lee i just figure it out its like to say: "translate (0.0 0.0 0.0) from WCS to current UCS" (trans '(0.0 0.0 0.0)0 1) Quote Link to comment Share on other sites More sharing options...
samifox Posted August 14, 2014 Author Share Posted August 14, 2014 Hi. Can i say that autolisp dont respect ucs at all and commands respect ucs by all means,? Quote Link to comment Share on other sites More sharing options...
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.