-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolygon.lisp
65 lines (43 loc) · 1.35 KB
/
polygon.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
;;(* 1 2)
;;(setf *pi* 3.14159)
;;(+ '(1 1.0) '(2 2))
(defclass polygon ()
(
(outside_radius :accessor outside_radius)
(no_of_sides :accessor no_of_sides)
(start_angle :accessor start_angle)
)
)
;(setf item (make-instance 'polygon))
(defun polygon_angle_rad (no_of_sides)
"`polygon_angle_rad' returns the center angle
`no_of_sides' number of sides
"
(/ (* 2 *pi*) no_of_sides)
)
(defun polygon_angle_deg (no_of_sides)
(/ 360.0d0 no_of_sides))
(assert (< (- (polygon_angle_rad 4.0d0) (/ *pi* 2.0)) 1e-9))
(assert (< (- (polygon_angle_deg 4) 90.0d0) 1.0))
(defun get-points-of-polygon (center outside_radius no_of_sides)
(let ((angle (polygon_angle_rad no_of_sides))
(Xc (x-of center))
(Yc (y-of center))
(Zc (z-of center))
)
(loop for i from 1 upto no_of_sides
collect (list
(+ Xc (* outside_radius (cos (* i angle))))
(+ Yc (* outside_radius (sin (* i angle))))
Zc))))
(defun gcode_polygon (center outside_radius no_of_sides output-stream)
(let ((point_list
(get-points-of-polygon center outside_radius no_of_sides)
))
(loop for point in point_list
do (linear-move point 900.0 output-stream))
))
(format *standard-output* "------~%")
(format *standard-output* "(polygon at ~a)"
(gcode_polygon '(0.0d0 0.0d0 6.0d0) 8.0 6 *standard-output*)
(format *standard-output* "------~%")