本帖最后由 陨落 于 2015-12-9 09:57 编辑
话不多说,直接上源码- (defun num*vec(num vec);;;;;向量数乘
- (mapcar '(lambda(x) (* x num)) vec))
- (defun vec+vec(vec1 vec2);;;;;向量相加
- (if (= (length vec1) (length vec2))
- (mapcar '(lambda (x y)(+ x y))vec1 vec2)
- (princ "\n出错:向量长度不一致")))
- (defun vec-vec(vec1 vec2);;;;;向量相减
- (if (= (length vec1) (length vec2))
- (mapcar '(lambda (x y)(- x y))vec1 vec2)
- (princ "\n出错:向量长度不一致")))
- (defun vec*vec(vec1 vec2);;;;;向量数量积
- (if (= (length vec1) (length vec2))
- (apply '+(mapcar '(lambda (x y)(* x y))vec1 vec2))
- (princ "\n出错:向量长度不一致")))
- (defun vecmod(vec);;;;;;向量的模
- (sqrt(apply '+(mapcar '(lambda(x)(* x x)) vec))))
- (defun pervec(pt1 pt2);;;;两点之间的单位向量
- (setq vecs(vec-vec pt2 pt1))
- (num*vec(/ 1(vecmod vecs))vecs)
- )
|