Ray-casting algorithm: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: used a better over/under statement construct.) |
(→{{header|Racket}}: Added missing implementation details from algorithm.) |
||
Line 2,993: | Line 2,993: | ||
(module pip racket |
(module pip racket |
||
(require racket/contract) |
(require racket/contract) |
||
(provide point) |
(provide point) |
||
(provide seg) |
(provide seg) |
||
Line 3,002: | Line 3,002: | ||
(struct point (x y) #:transparent) |
(struct point (x y) #:transparent) |
||
(struct seg (Ax Ay Bx By)) |
(struct seg (Ax Ay Bx By) #:transparent) |
||
(define ε 0.000001) |
(define ε 0.000001) |
||
(define (neq? x y) (not (eq? x y))) |
(define (neq? x y) (not (eq? x y))) |
||
Line 3,013: | Line 3,013: | ||
(eq? Pyo By)) |
(eq? Pyo By)) |
||
ε 0))]) |
ε 0))]) |
||
( |
(define Ax2 (if (< Ay By) Ax Bx)) |
||
(define Ay2 (if (< Ay By) Ay By)) |
|||
(define Bx2 (if (< Ay By) Bx Ax)) |
|||
(define By2 (if (< Ay By) By Ay)) |
|||
(cond [(or (> Py (max Ay By)) (< Py (min Ay By))) #f] |
|||
[(> Px (max Ax Bx)) #f] |
[(> Px (max Ax Bx)) #f] |
||
[ |
[else (cond |
||
[ |
[(< Px (min Ax Bx)) #t] |
||
[else |
|||
(let ([red (if (neq? Ax2 Bx2) |
|||
(/ (- By2 Ay2) (- Bx2 Ax2)) |
|||
+inf.0)] |
|||
[blue (if (neq? Ax2 Px) |
|||
(/ (- Py Ay2) (- Px Ax2)) |
|||
+inf.0)]) |
|||
(if (>= blue red) #t #f))])]))) |
|||
(define (point-in-polygon? point polygon) |
(define (point-in-polygon? point polygon) |