Hippe013 Posted November 10, 2015 Share Posted November 10, 2015 I have the following code that transforms a point using the transformation matrix returned by NENTSEL from Model to World. (defun SXH:transmatrix (mat p) (setq x (+ (* (car (nth 0 mat)) (car p)) (* (car (nth 1 mat)) (cadr p)) (* (car (nth 2 mat)) (caddr p)) (car (nth 3 mat)))) (setq y (+ (* (cadr (nth 0 mat)) (car p)) (* (cadr (nth 1 mat)) (cadr p)) (* (cadr (nth 2 mat)) (caddr p)) (cadr (nth 3 mat)))) (setq z (+ (* (caddr (nth 0 mat)) (car p)) (* (caddr (nth 1 mat)) (cadr p)) (* (caddr (nth 2 mat)) (caddr p)) (caddr (nth 3 mat)))) (list x y z) ) I need to make a transformation from World to Model. How would I set up this inverse matrix? Any help is appreciated! regards, Hippe013 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 10, 2015 Share Posted November 10, 2015 Here is another way to write your function (using mxv from here): (mapcar '+ (mxv (reverse (cdr (reverse mat))) p) (last mat)) Note that this is only applicable to the nentsel matrix and not the nentselp matrix, due to the difference in the matrix structure, as described here. To inverse the matrix, you may use the invm function from here - though, you will need to convert your matrix to be a square matrix, as returned by nentselp. Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted November 10, 2015 Author Share Posted November 10, 2015 Lee, I appreciate your help! You have a very elegant way of writing code. (mapcar '+ (mxv (reverse (cdr (reverse mat))) p) (last mat)) Worked like a charm! So.... My next question is how do I convert my matrix as returned by NENTSEL to a square matrix as required by your INVM function? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 10, 2015 Share Posted November 10, 2015 Thank you So.... My next question is how do I convert my matrix as returned by NENTSEL to a square matrix as required by your INVM function? The matrix is transposed, with the vector row in the nentsel matrix becoming the last column in the nentselp matrix, and with an additional (0 0 0 1) row to yield a square matrix - this is described in the link I provided above, and in the linked post I have also provided a function to perform this conversion. However, why not simply use nentselp over nentsel? Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted January 19, 2016 Author Share Posted January 19, 2016 Lee, It has been a while since I've been working with transformations. I am currently working on an ObjectDBX project where I am copying objects from an XREF which has been successful. What I need to do next is transform all the copied objects. I have a variant of vla-objects as returned by vla-CopyObjects and the matrix as returned by nentsel. How would you approach this? Any help is always appreciated. regards, Hippe013 Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted January 19, 2016 Author Share Posted January 19, 2016 Lee, Moreover I would like to know how to convert the matrix returned by nentsel to the matrix required by vlax-TMatrix. regards, Hippe013 Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted January 19, 2016 Author Share Posted January 19, 2016 Nevermind Lee! I figured it out! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 19, 2016 Share Posted January 19, 2016 I am currently working on an ObjectDBX project where I am copying objects from an XREF which has been successful. What I need to do next is transform all the copied objects. I have a variant of vla-objects as returned by vla-CopyObjects and the matrix as returned by nentsel. How would you approach this? See: http://www.theswamp.org/index.php?topic=39876.msg451779#msg451779 Moreover I would like to know how to convert the matrix returned by nentsel to the matrix required by vlax-TMatrix. See: http://www.theswamp.org/index.php?topic=40546.msg458445#msg458445 Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted January 20, 2016 Author Share Posted January 20, 2016 Ok... So, I've read through the links that you provided and it's a wealth of information and thank you for that. I had thought that I had everything working right. I had tested on lines with an XREF, but when I tested on a block within the XREF nentselp returns a different matrix than when selecting a line. So, with that said I figure that I need to build the matrix using info from the XREF itself. I.e. Insertion point, x y z scale, and rotation. I'll have to study your links a bit more to figure out how to build said matrix. Your help is greatly appreciated! Thank you lee. My end goal is to select an object within an XREF, figure which layer the object is on and then copy all those objects that are on the same layer into the current drawing similar to ncopy but all objects on the same layer. Regards, Hippe013 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.