samifox 发表于 2022-7-5 22:48:10

Lee Mac-几何函数ex

你好
 
学习Lee的几何函数,从垂直-p()开始
 
什么是vxv,十进制1e-8的平均值是多少?
 

;; Perpendicular-p-Lee Mac
;; Returns T if vectors v1,v2 are perpendicular

(defun LM:Perpendicular-p ( v1 v2 )
   (equal 0.0 (vxv v1 v2) 1e-8)
)

MSasu 发表于 2022-7-5 22:54:25

该函数表示2个向量的点积(与叉积相反)。李收藏:
;; Vector Dot Product-Lee Mac
;; Args: u,v - vectors in R^n

(defun vxv ( u v )
   (apply '+ (mapcar '* u v))
)
1e-8是在-8处提出的10的科学记数法,用于简化此类数字的书写;其等效于:
(expt 10.0 -

hanhphuc 发表于 2022-7-5 23:02:51

李Mac很好的编码风格简单但很有效!!
 
要达到他的水平还有很长的路要走
这里只是分享另一种方法
我的版本3线余弦

(defun per-p (a b c fuzz)
(equal ( / pi 2)
('((d )
    (if
      (equal (abs d) 1. 1e-16)
   0.
   (+ (* 2. (atan 1.)) (atan (/ d (sqrt (- 1. (* d d ))))) ); (* 2. (atan 1.))= (/ pi 2)
   )
    )
   (/ (+ (* a a) (* b b) (-(* c c)))(* 2. a b))
   )
fuzz)
) ;_ end of defun

(per-p 3. 4. 5. 1e-16); T

*删除编辑注释

samifox 发表于 2022-7-5 23:07:45

你好
我总是按点处理实体,在这个函数中,预期的实体是向量,我该如何使用它?有人能举个例子吗?
 
谢谢
S

hanhphuc 发表于 2022-7-5 23:17:59

应用数学
面积公式:
|x1 x2 x3 x4 xn|
|   \/\/\/\/\/   |
|.    /\/\/\/\/\   |
|y1 y2 y3 y4 yn.|。1/2
 

;hanhphuc 07/07/2014
(defun 2d-area (l)
(abs
   (/ (apply '-
      (mapcar '(lambda (x y)
   (vxv; sub function by LEE MAC
   (mapcar '(eval x) l)
   (mapcar '(eval y)
      (append (cdr l) (list (car l)))
   )
   ) ;_ vxv
      ) ;_ end of lambda
       '(car cadr)
       '(cadr car)
      ) ;_ end of mapcar
      ) ;_ end of apply
      2.
   ) ;_ end of /
   
);_ end of abs

) ;_ end of defun


 
;测试:
(2d区域'((0.0 0.0)(4.0 0.0)(4.0 3.0)))
;6

samifox 发表于 2022-7-5 23:21:55

 
对不起,我还是不明白。。。能简单一点吗?

hanhphuc 发表于 2022-7-5 23:24:56

 
嗨,希望这有帮助?
 
http://dl.dropboxusercontent.com/u/25241751/Shared%20SM/GIF%20Demo/Area.PNG
 
如果我给你错了方向,请告诉我,谢谢

BIGAL 发表于 2022-7-5 23:35:12

1e-8用于改进两个值的比较,其中一个值的小数位数较多,不返回true
 
V1=123.123
v2=123.12300003
v1不等于v2,但考虑到数量公差,它是。

samifox 发表于 2022-7-5 23:42:08

 
感谢您的视觉解释,
 
vxv()比较3个给定坐标的x.y,然后乘和除它们的分量,以获得面积,太酷了!
 
但是它与向函数传递向量有什么关系呢?
 
谢谢
谢伊

samifox 发表于 2022-7-5 23:42:41

有人吗?只需要知道如何将2个向量传递给Mac Lee的函数
 

;; Perpendicular-p-Lee Mac
;; Returns T if vectors v1,v2 are perpendicular

(defun LM:Perpendicular-p ( v1 v2 )
   (equal 0.0 (vxv v1 v2) 1e-
)
页: [1] 2
查看完整版本: Lee Mac-几何函数ex