Find the intersection of two lines: Difference between revisions
Content added Content deleted
(Add emacs lisp) |
m (Add error message to emacs lisp) |
||
Line 966: | Line 966: | ||
(defun calculate-intersection (line1 line2) |
(defun calculate-intersection (line1 line2) |
||
( |
(if (= (plist-get line1 'a) (plist-get line2 'a)) |
||
(progn (error "The two lines don't have any intersection.") nil) |
|||
⚫ | |||
(progn |
|||
⚫ | |||
(let (int-x int-y) |
|||
(setq int-y (+ (* (plist-get line1 'a) int-x) (plist-get line1 'b))) |
|||
(setq int-x (/ (- (plist-get line2 'b) (plist-get line1 'b)) |
|||
⚫ | |||
⚫ | |||
(list 'x int-x 'y int-y) ) ) ) ) |
|||
(let ((p1 '(x 4.0 y 0.0)) (p2 '(x 6.0 y 10.0)) |
(let ((p1 '(x 4.0 y 0.0)) (p2 '(x 6.0 y 10.0)) |
||
Line 976: | Line 979: | ||
(let ((line1 (line-prop p1 p2)) |
(let ((line1 (line-prop p1 p2)) |
||
(line2 (line-prop p3 p4))) |
(line2 (line-prop p3 p4))) |
||
(message "%s" (calculate-intersection line1 line2) |
(message "%s" (calculate-intersection line1 line2)) ) ) |
||
) |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||