Friday, June 6, 2014

Arithmetic And Geometric Functions


Arithmetic Functions


That is important. In an arithmetic function the mathematical symbol always comes before the arguments.


(+ <number> <number> ...)


The plus sign is a mathematical symbol.


Examples:


Function Gives back


(+ 1 2) 3
(+ 12 13) 25
(+ 1 2 3 4 5) 15


(- <number> <number> ...)


Examples:


Function Gives back


(- 50 40) 10
(- 40 30 5 0) 5
(- 10 20) -10


(* <number> <number> ...)


Examples:


Function Gives back



(* 2 3) 6
(* 12 15 2) 360
(* 3 -4.5) -13.5


(/ <number> <number> ...)


Function Gives back



(/ 100 2) 50
(/ 100 2.0) 50.0
(/ 100 20 2) 5


(1+ <number>)


Example:



Function Gives back



(1+ 5) 6


(1- <number>)


Example:



Function Gives back



(1- 10) 9


(abs <number>)


This function gives the absolute value of the number. The number can be a real number of an integer.


Examples:


Function Gives back


(abs 100) 100
(abs -97.25) 97.25


(max <number> <number> ...)


This function gives back the number that is the maximum of all the numbers. The number can be a real number or an integer.


Examples:


Function Gives back


(max 12 20) 20
(max 5,5 7) 7


(min <number> <number> ...)


This function is the opposite of the previous function. Now the minimum number is given back. The number can be a real number or an integer.


Examples:


Function Gives back


(min 4.07 -144) -144
(min 88.5 19 5) 5


(gcd <number> <number>)


Now we are going to do a complicated calculation.With this function the greatest common divisor is found. The numbers are integers.


Examples:


Function Gives back



(gcd 81 57) 3
(gcd 12 20) 4


(rem <number> <number> ...)


This function calculates how much remains after a division. The numbers can be integers and real numbers.


Examples:



Function Gives back



(rem 42 12) 6
(rem 9 4) 1



(exp <number>)


This function raises e to the mach of the number. The number can be an integer as a real number. The result is always positive.


Examples:


Function Gives back



(exp 1) 2.71828
(exp 2.2) 9.02501
(exp -0.4) 0.67032


(expt <base> <exponent>)


Now the base number is raised to the mach of the exponent number. The base and the exponent can be integers and real numbers.


Examples:


Function Gives back



(expt 2 4) 16
(expt 3.0 2) 9.0


(sqrt <number>)


This function calculates the square root of the number. The number can be an integer as well as a real number.


Examples:


Function Gives back



(sqrt 9) 3
(sqrt 2.0) 1.41321


(log <number>)


This function gives as result the natural logarithm of the number. The number can be an integer as well as a real number.


Examples:


Function Gives back



(log 4.5) 1.50408
(log 1.22) 0.198851


pi


This is no function but a constant number. The value of the number is 3.1415926.


Geometric Functions


(cos <angle>)


This function calculates the cosinus of an angle. The angle is expressed in radians.


Examples:



Function Gives back



(cos 0) -1
(cos pi) 1



(sin <angle>)


The same as before. Except this time the sinus of an angle is calculated. The angle is expressed in radians.


Examples:


Function Gives back



(sin 1.0) 0.841471
(sin 0,0) 0.0


(atan <number> [<number>])


If the second number is not present, then the function gives back the tangent of the first number in radians.


The number of the angle can be between pi and -pi,


Examples:


Function Gives back



(atan 0.5) 0.463648
(atan 1.0) 0.785398
(atan -1.0) -0.785398


If the second number is present, then the function gives back the inverse tangent of the quotient of the two numbers.


Examples:



Function Gives back



(atan 2.0 3.0) 0.588003
(atan -2.0 3.0) -0.68003
(atan -2.0 -3.0) -2.55359
(atan 1.0 0.0) 1.570796
(atan -0.5 0.0) -1.570796


(angle <point1> <point2>)


The function calculates the angle of the straight line going from point1 to point2. It calculates the angle between the line and the active UCS.


UCS stands for User Coordinate System. And the angles are measured counter clockwise. And the angle is given in radians.


Examples:


Function Gives back



(angle '(1.0 1.0) '(1.0 4.0)) 1.5708
(angle '(5.0 1.33) '(2.4 1.33)) 3.14159


(distance <point1> <point2>)


The function gives the distance between the two points. The distance is given in screen units.


If the value of the FLATLAND system variable is unequal to zero, then 2D points are expected. If a 3D point is used, then the Z value is ignored.


Examples:
Function Gives back



(distance '(1.0 2.5 3.0)
'(7.7 2.5 3.0)
) 6.7
(distance '(1.0 5.0)
'(1.0 15.0)
) 10.0


(inters <point1> <point2> <point3> <point4> [<on>])


The function calculates where the lines between point 1 and point 2 and point 3 and point 4 cross. A point is given back.


When the optional argument ON is present and nil. Then the two lines are considered to be infinite.


Examples:


(setq p1 (list 1.0 1.0)
p2 (list 9.0 9.0)
p3 (list 4.0 1.0)
p4 (list 4.0 2.0)
)


Function Gives back



(inters p1 p2 p3 p4) nil
(inters p1 p2 p3 p4 T) nil
(inters p1 p2 p3 p4 nil) (4.0 4.0)


(polar <point> <angle> <distance>)


This function gives as a result a point that is under an angle from the point that has been given and on the distance.


Example:


Function Gives back



(polar '(1.0 1.0) 0 4.0) (5.0 1.0)


(osnap <point> <mode>)


Depending on the value of the text of the mode a point is calculated. These are the modes there
are:


Mode Description


nea” Nearest snap
endp” Endpoint snap
midp” Midpoint snap
centre” Center snap
perp” Perpendicular snap
tan” Tangent snap
quad” Quadrant snap
int” Insertion point snap
pnt” Point Snap
int” Intersection snap



Example:


Function



(setq pt (osnap pt “nea”))


Exercises



1. Write the following arithmetic functions:


- 12 plus 13
- 8 times 5
- 200 divided by 4
- What is maximum of 12, 25 3 2, 94?
- What is the greatest common divisor of 256 and 326?
- What is the 8th power of 3?


2. Using geometric functions:


- What is the angle of a horizontal line? From left to right and from right to left.
- What is the distance between the points 10,20 and 40,50?
- What point is found starting in punt 10,20 and under an angel of 45 degrees and over a distance of 25?


No comments:

Post a Comment