Jump to content

How to input spherical and cylindrical coordinates with autolisp?


andrew777

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by BIGAL
Link to comment
Share on other sites

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 by BIGAL
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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