球
例えば球の頂点データを作るのにたったこれだけっていうのは、やっぱり短いし楽だと思う。
(defun circle-xy(index step) (let ((radian (/ (* 2 pi index) (- step 1)))) (list (sin radian) (cos radian)))) (defun sphere-xyz(circle-xy index step) (let ((yz (let ((radian (/ (* pi index) (- step 1)))) (list (sin radian) (cos radian))))) (list (* (elt yz 0) (elt circle-xy 0)) (elt yz 1) (* (elt yz 0) (elt circle-xy 1))))) (defun sphere-vertices(radius slice-dim) (let ((radius radius)) (apply #'append (loop for i from 0 below (elt slice-dim 0) collect (loop for j from 0 below (elt slice-dim 1) collect (let ((seed (sphere-xyz (circle-xy i (elt slice-dim 0)) j (elt slice-dim 1)))) (list (mapcar #'(lambda (x) (* x radius)) seed) seed (list (/ i (- (elt slice-dim 0) 1)) (/ j (- (elt slice-dim 1) 1)))))))))) (defun sphere-indices(slice-dim) (let ((x (elt slice-dim 0)) (y (elt slice-dim 1))) (loop for i from 0 below (- x 1) collect (apply #'append (loop for j from 0 below y collect (list (+ (* i y) j) (+ (* (+ i 1) y) j)))))))