AutoLISP observes the following conventions for handling graphics coordinates. Points are expressed as lists of two or three numbers surrounded by parentheses.
Expressed as lists of two real numbers (X and Y, respectively), as in
(3.4 7.52)
Expressed as lists of three real numbers (X, Y, and Z, respectively), as in
(3.4 7.52 1.0)
list function to form point lists, as shown in the following examples:
You can use the_$ (listβ3.875 1.23)
(3.875β1.23)
_$ (list 88.0β14.77β3.14)
(88.0β14.77β3.14)
To assign particular coordinates to a point variable, you can use one of the following expressions:
_$ (setq pt1 (list 3.875 1.23))
(3.875β1.23)
_$ (setq pt2 (list 88.0 14.77 3.14))
(88.0β14.77β3.14)
_$ (setq abc 3.45)
3.45
_$ (setq pt3 (list abc 1.23))
(3.45β1.23)
abc as the X component of the point.
The latter uses the value of variablequote function to explicitly define the list, rather than the list function. The quote function returns an expression without evaluation, as follows:
If all members of a list are constant values, you can use the_$β(setq pt1 (quote (4.5 7.5)))
(4.5β7.5)
quote function. The following code produces the same result as the preceding code.
The single quotation mark (') can be used as shorthand for the_$β(setq pt1 '(4.5 7.5))
(4.5β7.5)
car, cadr, and caddr. The following examples show how to extract the X, Y, and Z coordinates from a 3D point list. The pt variable is set to the point (1.5 3.2 2.0):
You can refer to X, Y, and Z components of a point individually, using three additional built-in functions called_$β(setq pt '(1.5β3.2β2.0))
(1.5β3.2β2.0)
car function returns the first member of a list. In this example it returns the X value of point pt to the x_val variable.
The_$β(setq x_val (car pt))
1.5
cadr function returns the second member of a list. In this example it returns the Y value of the pt point to the y_val variable.
The_$β(setq y_val (cadr pt))
3.2
caddr function returns the third member of a list. In this example it returns the Z value of point pt to the variable z_val.
The_$β(setq z_val (caddr pt))
2.0
pt1 and pt2) corners of a rectangle, as follows:
You can use the following code to define the lower-left and upper-right (_$β(setq pt1 '(1.0 2.0) pt2 ' (3.0 4.0))
(3.0β4.0)
car and cadr functions to set the pt3 variable to the upper-left corner of the rectangle, by extracting the X component of pt1 and the Y component of pt2, as follows:
You can use the_$β(setq pt3 (list (car pt1) (cadr pt2)))
(1.0β4.0)
pt3 equal to point (1.0,4.0).
The preceding expression setscar and cdr up to four levels deep. The following are valid functions:
AutoLISP supports concatenations ofcaaaar |
cadaar |
cdaaar |
cddaar |
caaadr |
cadadr |
cdaadr |
cddadr |
caaar |
cadar |
cdaar |
cddar |
caadar |
caddar |
cdadar |
cdddar |
caaddr |
cadddr |
cdaddr |
cddddr |
caadr |
caddr |
cdadr |
cdddr |
caar |
cadr |
cdar |
cddr |
car and cdr. Each a represents a call to car, and each d represents a call to cdr. For example:
These concatenations are the equivalent of nested calls to(caar x) is equivalent to (car (car x))
(cdar x) is equivalent to (cdr (car x))
(cadar x) is equivalent to (car (cdr (car x)))
(cadr x) is equivalent to (car (cdr x))
(cddr x) is equivalent to (cdr (cdr x))
(caddr x) is equivalent to (car (cdr (cdr x)))