andrew777 Posted September 28, 2016 Share Posted September 28, 2016 I want to write a routine that converts a text file of Cartesian coordinates to either spherical or cylindrical coordinates. What is the method and format, for example for the command function to draw a line in autolisp with spherical and cylindrical coordinates. I know how to input manually these coordinates but I don't know how to do it automatically with AutoLISP. Any help will be appreciated. Thanks, Andrew Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted September 28, 2016 Share Posted September 28, 2016 Use functions : (sin x) and (cos x) Quote Link to comment Share on other sites More sharing options...
scj Posted September 29, 2016 Share Posted September 29, 2016 The general syntax for spherical coordinates is length or for relative coordinates @ length The general syntax for cylindrical coordinates is length or for relative cylindrical coordinates @length You can use this in Lisp - see the example (setq l1 1000) (setq w1 90) (setq w2 -90) (setq pt (strcat "@" (rtos l1) " @1000.0000 Hope this helps Regards Jochen http://www.ant-ares.de Quote Link to comment Share on other sites More sharing options...
andrew777 Posted September 29, 2016 Author Share Posted September 29, 2016 Hello scj, You gave me the method that I needed. Sometimes spherical and cylindrical allows me to create objects easier. Thank you, Andrew Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 29, 2016 Share Posted September 29, 2016 I would suggest researching the AutoLISP polar function. Quote Link to comment Share on other sites More sharing options...
andrew777 Posted September 29, 2016 Author Share Posted September 29, 2016 Hello Lee Mac, I am using a spherical and cylindrical routine to input 3-D objects into AutoCAD. I only wanted to alter my routine to to the syntax for spherical and cylindrical input in AutoLISP. I can't see why the study of the polar function would help. scj understood what I was trying to convey. Many people are experts on this site and you are one of them, however scj gave me what I wanted. Interpreting someone's email can be hit or miss. Your assistance is always welcome. Thanks, Andrew Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 30, 2016 Share Posted September 30, 2016 (edited) I agree with Lee and Marco looking into polar function will answers questions further down the track. basic angle functions o/h = sin(ang) a/h = cos(ang) o/a = tan(ang) others have a habit of answering (defun dtr (a) (* pi (/ a 180.0)) ) (defun tan (a) (setq a (dtr a)) (/ (sin a)(cos a)) ) (setq orgpt (list 0 0 0)) ; set your base pt (setq pt (polar orgpt (dtr w1) L1)) (setq z (* l1 (tan (dtr w2)))) (setq pt (list (car pt)(cadr pt)(+ z (caddr pt))) Edited September 30, 2016 by BIGAL Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 30, 2016 Share Posted September 30, 2016 (edited) A bit of fun (defun dtr (a) (* pi (/ a 180.0)) ) (defun tan (a) (setq a (dtr a)) (/ (sin a)(cos a)) ) (setq cenpt (list 0 0 0)) (setq ang1 0.0) (setq ang2 0.0) (setq rad 1000.0) (repeat 59 (repeat 59 (setq pt (polar cenpt ang1 rad)) (setq pt (list (car pt)(cadr pt)(+ (* rad (tan (dtr ang2)))) )) (command "point" pt) (setq ang1 (+ ang1 6.0)) ) (setq ang2 (+ ang2 6.0)) ) (command "-vpoint" "1,1,1") Edited September 30, 2016 by BIGAL Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 30, 2016 Share Posted September 30, 2016 I am using a spherical and cylindrical routine to input 3-D objects into AutoCAD. I only wanted to alter my routine to to the syntax for spherical and cylindrical input in AutoLISP. I can't see why the study of the polar function would help. scj understood what I was trying to convey. The existing suggestion is restricted to basic command-line input, however, if you were to generate objects using any other means (such as ActiveX or entmake, for example), the points would need to be expressed as a cartesian point list. As such, the AutoLISP polar function will allow you to calculate a point at a given angle & radius from a base point. Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted September 30, 2016 Share Posted September 30, 2016 The existing suggestion is restricted to basic command-line input, however, if you were to generate objects using any other means (such as ActiveX or entmake, for example), the points would need to be expressed as a cartesian point list. As such, the AutoLISP polar function will allow you to calculate a point at a given angle & radius from a base point. FYI, polar function is derived from (sin ang) and (cos ang) functions... So actually no need for polar as must... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 30, 2016 Share Posted September 30, 2016 FYI, polar function is derived from (sin ang) and (cos ang) functions... So actually no need for polar as must... Of course there are other methods, but the equivalent of: (polar pnt ang dis) Using sin/cos would be: (mapcar '+ pnt (list (* dis (cos ang)) (* dis (sin ang)))) Which is unnecessary. 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.