马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
 - ;;; ------------------------------------------------------------------------
- ;;; 函数名称 / Function Name: XD::GEOM:VECTOR-SIDE
- ;;;
- ;;; 【功能说明 / Description】
- ;;; 判断三点构成向量的相对方向,返回点 P1 相对于从 P2 指向 P3 向量的方向。
- ;;; Determines the relative direction of point P1 to the vector from P2 to P3.
- ;;;
- ;;; 功能包括 / Features:
- ;;; - 计算两个向量 P2->P3 和 P2->P1 的叉积
- ;;; Compute cross product of vectors P2->P3 and P2->P1
- ;;; - 判断 P1 在该向量左侧、右侧,或共线
- ;;; Determine whether P1 is to the left, right, or colinear with vector P2->P3
- ;;; - 使用模糊容差处理浮点误差
- ;;; Use a fuzzy tolerance to handle floating-point precision issues
- ;;;
- ;;; 【参数说明 / Parameters】
- ;;; P1 - 点(x y),待判断位置的点 / Point whose relative position is to be determined
- ;;; P2 - 点(x y),起点 / Start point of reference vector
- ;;; P3 - 点(x y),终点 / End point of reference vector
- ;;;
- ;;; 【返回值 / Return Value】
- ;;; -1:P1 在向量 P2->P3 的右侧(右手规则)
- ;;; 0:三点共线
- ;;; +1:P1 在向量左侧
- ;;;
- ;;; 【依赖函数 / Dependencies】
- ;;; - XD::GEOM:LIST-FUZ : 计算三点之间适当的浮点容差 / Computes suitable fuzzy tolerance
- ;;; - XD::CALC:ROUND : 模糊舍入函数 / Rounds value with specified fuzziness
- ;;;
- ;;; 【使用示例 / Example Usage】
- ;;; (XD::GEOM:VECTOR-SIDE '(1 1) '(0 0) '(0 2)) => 1 ; P1 在左侧
- ;;; (XD::GEOM:VECTOR-SIDE '(0 -1) '(0 0) '(1 0)) => -1 ; P1 在右侧
- ;;; (XD::GEOM:VECTOR-SIDE '(1 0) '(0 0) '(2 0)) => 0 ; 共线
- ;;;
- ;;; 【备注 / Notes】
- ;;; - 返回值可用于多边形方向判断、点在边哪一侧等空间分析任务
- ;;; Useful for polygon orientation, spatial side testing, etc.
- ;;; ------------------------------------------------------------------------
- (defun XD::GEOM:VECTOR-SIDE (p1 p2 p3 / a dx dx1 dy dy1 fuz)
- ;; 计算向量 P2->P3 的 x 和 y 分量
- (setq dx (- (car p3) (car p2)))
- (setq dy (- (cadr p3) (cadr p2)))
-
- ;; 计算向量 P2->P1 的 x 和 y 分量
- (setq dx1 (- (car p1) (car p2)))
- (setq dy1 (- (cadr p1) (cadr p2)))
-
- ;; 计算三点之间的模糊容差
- (setq fuz (XD::GEOM:LIST-FUZ (list p1 p2 p3)))
-
- ;; 计算向量叉积 dx*dy1 - dy*dx1
- (setq a (- (* dx dy1) (* dy dx1)))
-
- ;; 应用模糊舍入处理误差
- (setq a (XD::CALC:ROUND a fuz))
-
- ;; 若非零则将结果归一化为 -1 或 +1(方向)
- (if (/= 0.0 a)
- (progn (setq a (/ a (abs a)))))
-
- ;; 返回方向:-1, 0, 或 1
- a
- )
|