我的GIS/CS學習筆記:https://github.com/yunwei37/ZJU-CS-GIS-ClassNotes
<一個浙江大學大學生的計算機、地理資訊科學知識庫 >
寫入下列三道題的LISP程式,并在實習報告中對運作結果截圖,簡略描述程式思路。
1、 有的兩位數具有一種有趣的性質:該數的平方分成兩個兩位數,它們的和等于該數本身。例如:552=3025,而55=30+25,程式設計,找出具有這樣性質的全部兩位數
(defun c:xinzhi ( / n n1 n2 s) ;該數的平方分成兩個兩位數,它們的和等于該數本身。
(setq n 10)
(while (<= n 99) (setq n1 (/ ( * n n ) 100))
(setq n2 ( - ( * n n ) (* n1 100)))
(setq s (+ n1 n2))
(if (= s n) (princ (strcat "\n" (rtos n)))
) ;if_end
(setq n (+ n 1))
) ;while_end
(princ)
) ;end
效果:
2、 程式設計,畫極坐标方程R=1+2cos(2θ)在[0, 2π]内的曲線
(command "pline" ) ;畫極坐标方程R=1+2cos(2θ)在[0, 2π]内的曲線
(setq n 0)
(repeat 3600
(command (polar (list 0 0) (/ n 57.3) ( + 1 ( * 2 ( cos ( * 2 (/ n 57.3) ) ) ) ) ))
(setq n ( + 0.1 n))
)
(command)
(command "pline" ) ;繪制阿基米德螺旋線
(setq n 0)
(repeat 1000
(command (polar (list 0 0) (/ n 57.3) n))
(setq n (1+ n))
)
(command)